我正在制作一个Windows 10通用应用程序,希望用户选择一个文件夹来保存应用程序的文档文件。该文件夹的路径保存在ApplicationData.Current.RoamingSettings.Values
中。
以下是代码:
首次启动:
var folderPicker = new FolderPicker { SuggestedStartLocation = PickerLocationId.ComputerFolder };
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
StorageFolder homeFolder = await folder.CreateFolderAsync("App1 Data", CreationCollisionOption.OpenIfExists);
var save = ApplicationData.Current.RoamingSettings.Values;
save["HomeFolder"] = homeFolder.Path;
当设置了HomeFolder时:
string dir = save["HomeFolder"].ToString();
try
{
StorageFolder homeFolder = await StorageFolder.GetFolderFromPathAsync(dir);
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
第二个代码示例中抛出的异常是:
System.UnauthorizedAccessException:访问被拒绝(来自HRESULT的异常:0x80070005(E_ACCESSDENIED))
所以我的问题是,你如何正确使用GetFolderFromPathAsync函数? 我检查了所有路径的字符串,它们都是正确的,即使
StorageFolder.GetFolderFromPathAsync(storageFolder.Path);
也不起作用。 你知道解决方法吗?