【问题标题】:Windows 8 StorageFile.GetFileFromPathAsync Using UNC PathWindows 8 StorageFile.GetFileFromPathAsync 使用 UNC 路径
【发布时间】:2013-03-03 20:14:59
【问题描述】:

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

According to the official documentation here

可以连接到 UNC 路径

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

但我不断收到拒绝访问错误。

谁能给我一个可行的例子 这让我发疯,并且真的质疑 Win 8 dev 的 LOB 应用程序的全部意义。

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;

            }
        }

【问题讨论】:

    标签: file windows-8 unc


    【解决方案1】:

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

    文件好像打不开,但是可以复制。 (这就是我最初想要实现的目标)

    希望对你有帮助

    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;
    
            }
        }
    

    【讨论】:

    • 确实,我认为这是唯一的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    相关资源
    最近更新 更多