【问题标题】:UWP FolderPicker does not grant me permission to access folderUWP FolderPicker 不授予我访问文件夹的权限
【发布时间】:2018-10-05 00:12:58
【问题描述】:

以下代码取自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 功能添加到应用程序清单。我在这里错过了什么?

【问题讨论】:

    标签: c# uwp


    【解决方案1】:

    broadFileSystemAccess 仅适用于Windows.Storage 命名空间,这在docs 中已经提到如下:

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

    文件系统。如果您将应用程序提交到声明此功能的应用商店,您将需要提供额外说明,说明原因 您的应用需要此功能,以及它打算如何使用它。这 功能适用于 Windows.Storage 命名空间中的 API

    【讨论】:

    • 谢谢。因此,在使用UWP 应用程序时,没有办法在特定文件夹上运行Process.Start()
    • 我不知道 process.start 是什么,你这里的用例是什么?
    • 您可以使用Launcher.LaunchFolderAsync在文件资源管理器中打开文件夹
    • @touseefbsb:对不起,我有点含糊。我的意思是这样的stackoverflow.com/a/181857/368599(或者像Directory.Exists("D:/my_dir");这样简单的东西
    • @MartinZikmund:我需要在特定文件夹中运行一个进程。我有一个已经这样做的图书馆。问题是当我从 UWP 应用程序调用库的函数(否则工作)时,我得到一个拒绝访问异常。
    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 2019-06-18
      • 1970-01-01
      • 2013-01-28
      • 2016-03-14
      • 1970-01-01
      相关资源
      最近更新 更多