【发布时间】:2017-02-13 20:13:50
【问题描述】:
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);
}
}
【问题讨论】:
标签: uwp