Windows 8 StorageFile.GetFileFromPathAsync使用UNC路径 [英] Windows 8 StorageFile.GetFileFromPathAsync Using UNC Path

查看:156
本文介绍了Windows 8 StorageFile.GetFileFromPathAsync使用UNC路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人曾经设法使用Windows 8应用程序将文件从unc目录复制到本地目录?

根据此处的官方文档

可以连接到UNC路径

我正在使用std FILE ACCESS示例,并将一行代码更改为如下所示 我添加了所有功能 添加.txt作为文件类型 UNC路径是所有人的读写路径,并且位于同一台计算机上.

但是我一直收到访问被拒绝的错误.

有人可以给我提供一个可行的例子吗? 这让我发疯,并真的质疑LOB应用程序赢得8开发的全部意义.

TIA

private async void Initialize()
        {
            try
            {
                //sampleFile = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFileAsync(filename);
                string myfile = @"\\ALL387\Temp\testfile.txt";
                sampleFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(myfile);

            }
            catch (FileNotFoundException)
            {
                // sample file doesn't exist so scenario one must be run
            }

            catch (Exception e)
            {
                var fred = e.Message;

            }
        }

解决方案

我已经解决了这个问题,而我发现最好的方法是创建一个文件夹对象 枚举文件夹对象中的文件 一次将一个文件复制到本地文件夹,然后访问它们

似乎您无法打开文件,但可以将其复制. (这是我最初试图实现的目标)

希望这会有所帮助

private async void Initialize()
    {
        try
        {

            var myfldr = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(@"\\ALL387\Temp");
            var myfiles = await myfldr.GetFilesAsync();

            foreach (StorageFile myfile in myfiles)
            {
                StorageFile fileCopy = await myfile.CopyAsync(KnownFolders.DocumentsLibrary, myfile.Name, NameCollisionOption.ReplaceExisting);
            }

            var dsd = await Windows.Storage.KnownFolders.PicturesLibrary.GetFilesAsync();

            foreach (var file in dsd)
            {
              StorageFile  sampleFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(file.Path);
            }


        }
        catch (FileNotFoundException)
        {
            // sample file doesn't exist so scenario one must be run
        }

        catch (Exception e)
        {
            var fred = e.Message;

        }
    }

Has anyone EVER managed to use a windows 8 app to copy files from a unc dir to a local dir ?

According to the official documentation here

It is possible to connect to a UNC path

I am using the std FILE ACCESS sample and have changed one line of code to read as below I have added all the capabilities Added .txt as a file type The UNC path is read write to everyone and is located on the same machine..

But I keep getting Access Denied Errors.

Can anyone possibly provide me with a working example This is driving me mad and really questioning the whole point of win 8 dev for LOB apps.

TIA

private async void Initialize()
        {
            try
            {
                //sampleFile = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFileAsync(filename);
                string myfile = @"\\ALL387\Temp\testfile.txt";
                sampleFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(myfile);

            }
            catch (FileNotFoundException)
            {
                // sample file doesn't exist so scenario one must be run
            }

            catch (Exception e)
            {
                var fred = e.Message;

            }
        }

解决方案

I have sorted this out and the way I found best to do it was to create a folder object enumnerate over the files in the folder object copy the files one at a time to the local folder then access them

It seems that you can't open the files, but you can copy them. ( which was what I was trying to achieve in the first place )

Hope this helps

private async void Initialize()
    {
        try
        {

            var myfldr = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(@"\\ALL387\Temp");
            var myfiles = await myfldr.GetFilesAsync();

            foreach (StorageFile myfile in myfiles)
            {
                StorageFile fileCopy = await myfile.CopyAsync(KnownFolders.DocumentsLibrary, myfile.Name, NameCollisionOption.ReplaceExisting);
            }

            var dsd = await Windows.Storage.KnownFolders.PicturesLibrary.GetFilesAsync();

            foreach (var file in dsd)
            {
              StorageFile  sampleFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(file.Path);
            }


        }
        catch (FileNotFoundException)
        {
            // sample file doesn't exist so scenario one must be run
        }

        catch (Exception e)
        {
            var fred = e.Message;

        }
    }

这篇关于Windows 8 StorageFile.GetFileFromPathAsync使用UNC路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆