在 UWP AppService 中访问 C 盘文件 [英] Access C Drive files in UWP AppService

查看:34
本文介绍了在 UWP AppService 中访问 C 盘文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 UWP AppService 中访问系统盘(C、D 盘)文件.示例:我想从 UWP AppServices 访问C:\Test\sample.txt"文件.

How to access the system drive(C, D drive) files in UWP AppService. Example: I want to access "C:\Test\sample.txt" file from UWP AppServices.

我尝试了以下代码.但抛出错误(附加信息:访问被拒绝.).并且还在 appxmanifest 文件中添加了可移动存储"功能.

I have tried the below code. but throwing error(Additional information: Access is denied.). And also added the "Removable Storage" Capabalities in appxmanifest file.

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);
    }
}

推荐答案

我很感激它来晚了,但是对于现在参考这篇文章的其他人来说,Microsoft 现在似乎已经添加了该功能.

I appreciate it's late, but for anyone else refering to this post now, it appears Microsoft have now added the capability.

只需将broadFileSystemAccess"功能添加到应用清单中,如下所述:https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions

Simply add the 'broadFileSystemAccess' capability to the app manifest as described here: https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions

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

Note that this still requires user input to some extent (the user must grant permission to file system access on first run of the app) but that the file/folder picker UI is not needed.

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

I haven't actually tried this yet but it sounds what you are after.

这篇关于在 UWP AppService 中访问 C 盘文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆