【问题标题】:Save and Open document files in Shared folder in Windows Phone 8.1在 Windows Phone 8.1 的共享文件夹中保存和打开文档文件
【发布时间】:2015-12-02 10:29:58
【问题描述】:

在我的 Windows Phone 8.1 + WIndows Store 8.1 应用程序中,需要下载文件并保存到某个共享位置。然后需要打开相同的文件,用户可以通过合适的本机/安装的应用程序选择/打开。

示例:我可以下载 .pdf,然后发出命令在 Adob​​e Acrobat/用户提供的应用程序中打开此文件。

下载到 LocalFolder 和 RoamingFolder 工作正常,但打开时会出现拒绝访问错误。

StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
var file = await local.CreateFileAsync(fileName,, CreationCollisionOption.ReplaceExisting); 
stream.Position = 0;
stream.CopyTo(await file.OpenStreamForWriteAsync());
return file.Path;

稍后,会调用以下函数从上面的代码中打开下载的文档

Windows.System.Launcher.LaunchUriAsync(new Uri(fileName));

请告诉我,如何将文件保存到任何共享文件夹或权限以使其可供其他应用访问并打开。提前致谢。

请注意,虽然答案不会有所不同,但我在 Xamarin 内的本机 Windows 应用程序解决方案中使用它。我已经在 Android 原生中实现了类似的功能,效果很好。

【问题讨论】:

    标签: xamarin windows-phone-8.1


    【解决方案1】:

    后来发现拒绝访问的错误不是Local或者Roaming文件夹,而是文件在创建的时候一直被代码打开。

    所以代码被替换为:

    StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
    var file = await local.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); 
    stream.Position = 0;
    using (Stream fileStream = await file.OpenStreamForWriteAsync())
            {
                stream.CopyTo(fileStream);
            }
    return file.Path;
    

    并且还要从应用程序打开文件,将代码替换为:

    StorageFile fileToLaunch = await StorageFile.GetFileFromPathAsync(fileName);
    bool done = await Windows.System.Launcher.LaunchFileAsync(fileToLaunch, new Windows.System.LauncherOptions { DisplayApplicationPicker = true });
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多