【问题标题】:How to add GetFileFromPathAsync's Path in Windows Store Apps如何在 Windows 应用商店应用程序中添加 GetFileFromPathAsync 的路径
【发布时间】:2012-12-03 14:52:13
【问题描述】:

我想分享一个文件路径给出的文件。单击共享魅力后,它说:来自我的应用程序的数据有问题。文件路径的正确格式是什么?

string filepath = "C:\Users\USER\Pictures\pic.png"; // bad format, unrecognized escape sequence
StorageFile file = await StorageFile.GetFileFromPathAsync(filepath);
args.Request.Data.SetStorageItems(new[] { file } );

我也试过了:

string filepath = "C:\\Users\\USER\\Pictures\\pic.png";
string filepath = @"C:\Users\USER\Pictures\pic.png";

提前致谢。

【问题讨论】:

    标签: c# windows-8 microsoft-metro windows-runtime windows-store-apps


    【解决方案1】:

    在 WinRT 中,您不能使用文件名直接引用文件。 Windows 应用商店应用程序可以使用的文件夹是有限的,并且只能使用适当的 API 访问。您可以在此处找到列表:http://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx

    特别是,因为您正试图访问图片文件夹中的图片,您需要使用 KnownFolders.PictureLibrary 位置。您还需要声明相关能力。请查看这篇文章以获取更多信息:http://danlb.blogspot.it/2011/11/winrt-file-access.html

    【讨论】:

    • 我已经声明了这个功能,所以我可以使用文件路径打开文件,这个问题在 Share 中弹出。使用 KnownFolders.PictureLibrary 的字符串声明怎么样,你能给我举个例子吗?
    【解决方案2】:

    你可以试试下面的代码:

    Windows.Storage.StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
    XDocument document = XDocument.Load(installedLocation.Path + @"/Assets/Configuration/Menu.xml");
    

    【讨论】:

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