【发布时间】:2019-10-30 01:30:05
【问题描述】:
我在我的 Windows 通用应用程序中使用 FolderPicker 让用户选择一个目录,当他们完成后,我需要访问该目录下已知子路径中的多个不同文件。我可以很好地选择目录,但是当我尝试从那里访问子路径中的东西时,我仍然被拒绝访问。有什么方法可以授予对父目录中多个文件的访问权限,而无需强制用户手动选择需要访问的每个文件?
这是我的代码,它打开文件夹选择器并将所选目录添加到我未来的访问列表中:
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
folderPicker.FileTypeFilter.Add("*");
Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null) {
StorageApplicationPermissions.FutureAccessList.AddOrReplace("GitDirectory", folder);
PathTextBox.Text = folder.Path;
this.IsPrimaryButtonEnabled = true;
}
(为我的命名约定道歉,我是 Win/C# 世界的新手,所以我以我所知道的大杂烩方式写作)
这是另一个试图访问子路径的类中的代码。您可以假设变量GitDirectory 之前已分配了调用FutureAccessList.GetFolderAsync("GitDirectory"); 的结果,因为它有:
StorageFile iniFile = await GitDirectory.GetFileAsync(@"datafiles\i18n\en_US.ini");
IniData data = iniParser.ReadFile(iniFile.Path);
正是这最后一行最终引发了这个异常:
Access to the path 'E:\Documents\git\asirra\datafiles\i18n\en_US.ini' is denied.
提前感谢您的帮助
【问题讨论】:
-
您尝试过广泛文件系统访问吗?
-
我可以使用它,因为这是一个供个人使用的应用程序,我不会将其提交到 Windows 商店,但是由于我将其用作学习体验,我想了解做我想做的事情的正确方法