Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在UWP AppService中访问C驱动器文件_Uwp - Fatal编程技术网

在UWP AppService中访问C驱动器文件

在UWP AppService中访问C驱动器文件,uwp,Uwp,如何在UWP AppService中访问系统驱动器(C,D驱动器)文件。 示例:我想从UWP AppServices访问“C:\Test\sample.txt”文件 我已经尝试了下面的代码。但是抛出错误(附加信息:访问被拒绝)。并在appxmanifest文件中添加了“可移动存储”功能 StorageFolder testfolder = await StorageFolder.GetFolderFromPathAsync(@"c:\\test"); StorageFile sourcefile

如何在UWP AppService中访问系统驱动器(C,D驱动器)文件。 示例:我想从UWP AppServices访问“C:\Test\sample.txt”文件

我已经尝试了下面的代码。但是抛出错误(附加信息:访问被拒绝)。并在appxmanifest文件中添加了“可移动存储”功能

StorageFolder testfolder = await StorageFolder.GetFolderFromPathAsync(@"c:\\test");
StorageFile sourcefile = await testfolder.GetFileAsync("sample.txt");
StorageFile destinationfile = await KnownFolders.SavedPictures.CreateFileAsync("Mysample.txt");
using (var sourcestream = (await sourcefile.OpenReadAsync()).GetInputStreamAt(0))
{
    using (var destinationstream = (await destinationfile.OpenAsync(FileAccessMode.ReadWrite)).GetOutputStreamAt(0))
    {
        await RandomAccessStream.CopyAndCloseAsync(sourcestream, destinationstream);
    }
}
如果没有用户交互,则只能打开特定位置(请参见)。正如@TheTanic所提到的,您只能通过用户交互(FileOpenPicker/FolderPicker)访问其他位置。当然,对于“纯”UWP应用服务来说,这是一个问题

这里有一种方法(我甚至不会称之为解决方案)只适用于非常狭窄的场景集:如果

  • 您知道所有文件都位于特定文件夹下,并且
  • 你至少有一些(最小的)用户界面是可以的
然后您可以执行以下操作:

  • 在UWP应用程序中托管AppService(请参阅)
  • 首次启动应用程序时向用户询问一次文件夹(使用FolderPicker)
  • 将该文件夹以特定名称存储在FutureAccessList(请参阅)中
  • 下次托管AppService的应用程序启动时,您可以从FutureAccessList中获取该文件夹

当然,在实践中,每次启动应用程序时,您都可以访问FutureAccessList,如果其中不包含文件夹,请询问用户。

我很感激时间太迟了,但对于现在引用本文的其他人来说,似乎Microsoft现在已经添加了该功能

只需将“broadFileSystemAccess”功能添加到应用程序清单中,如下所述:

请注意,这在某种程度上仍然需要用户输入(用户必须在应用程序第一次运行时授予文件系统访问权限),但不需要文件/文件夹选择器UI


我还没有真正尝试过这个,但这听起来像是你想要的。

我已经添加了这一点,但是许可授予在哪里发生?