新分析器:
我发现,Access denied
这只发生在台式机上,而不是移动设备上。后来,我找到了这篇文章,它描述了为什么会发生这种情况。这是因为权限处理,我放弃了我的权限。有几种可能如何处理这种情况:
例子:
FolderPicker folderPicker = new FolderPicker();
folderPicker.FileTypeFilter.Add("*");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
}
StorageFolder newFolder;
newFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("PickedFolderToken");
await newFolder.CreateFileAsync("test.txt");
例子:
StorageFolder tempFolder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(ApplicationData.Current.LocalCacheFolder.Path, "YourApp"));
StorageFile tempFile = await tempFolder.CreateFileAsync(Path.GetFileName(pathToAttachment), CreationCollisionOption.ReplaceExisting);
await file.CopyAndReplaceAsync(tempFile);
老答案:
我目前的解决方案是在我的应用程序中提供一个按钮,该按钮本机调用FolderPicker
viaDependencyService
并且仅在 UWP 上。有了这个,用户可以选择位置,然后我将文件复制到这个位置。效果很好,尽管我希望我不必只为一个平台做某事。