UWP FolderPicker不授予我访问文件夹的权限

时间:2018-10-05 00:12:59

标签: c# uwp

以下代码取自Microsoft's documentation,该主题经过细微修改:

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)
{
    // Application now has read/write access to all contents in the picked folder
    // (including other sub-folder contents)
    Windows.Storage.AccessCache.StorageApplicationPermissions.
    FutureAccessList.AddOrReplace("PickedFolderToken", folder);

    if (Directory.Exists(folder.Path)) // fails, I don't have permission to read this folder even though the documentation suggests that I should have access
    {
        this.textBlock.Text = "Picked folder: " + folder.Name; // never gets printed
    }
}

我还尝试将broadFileSystemAccess功能添加到应用程序清单中。我在这里想念什么?

2 个答案:

答案 0 :(得分:0)

broadFileSystemAccess 仅适用于Windows.Storage命名空间,并且已在docs中提到,如下所示:

  

这是受限制的功能。首次使用时,系统会提示   用户允许访问。可在“设置”>“隐私”中配置访问权限

     
    

文件系统。如果您向应用商店提交了声明此功能的应用,则需要提供有关原因的其他说明     您的应用需要此功能及其使用方式。这个     该功能适用​​于Windows.Storage命名空间中的API

  

答案 1 :(得分:0)

UWP应用程序的访问受到限制,常规的IO命令(包括System.Diagnostic.Process)不起作用。启动进程的唯一方法是使用https://docs.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.FullTrustProcessLauncher中的FullTrustProcessLauncher Class

可以在此处找到工作示例:https://github.com/StefanWickDev/UWP-FullTrust

但是,这不能解决使用现有库的问题,因为它们首先不是进程。现在,我们有了一个RPC服务,该服务从该服务发出请求并获得结果。