我正在创建一个应用程序,该应用程序的一个要求是能够允许用户通过更改文档文件夹中的文件夹并按下更新按钮来更改应用程序可以访问的数据 . 1.此应用程序无法访问互联网 . 2.访问Documents文件夹是一个特定的请求(我知道uwp是沙盒)3 . 本质上我试图将文件从文件存储中的文件夹移动到没有路径的本地存储(因为我无法访问它) . 这是我的尝试 .
class Copy
{
public async void update()
{
FolderPicker openPicker = new FolderPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".csv");
openPicker.FileTypeFilter.Add(".png");
openPicker.FileTypeFilter.Add(".txt");
StorageFolder updatefolder = await openPicker.PickSingleFolderAsync();
//CreateFileAsync("sample.dat", CreationCollisionOption.ReplaceExisting);
// Do something with the new file.
// Get the app's local folder to use as the destination folder.
StorageFolder mainFolder = ApplicationData.Current.LocalFolder;
// Set options for file type and sort order.
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".jpg");
fileTypeFilter.Add(".csv");
fileTypeFilter.Add(".png");
fileTypeFilter.Add(".txt");
QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
queryOptions.IndexerOption = IndexerOption.OnlyUseIndexer;
// Get the files in the user's document folder
// and its subfolders and sort them by date.
StorageFileQueryResult results = updatefolder.CreateFileQueryWithOptions(queryOptions);
// Iterate over the results and print the list of files
// to the Visual Studio Output window.
IReadOnlyList<StorageFile> sortedFiles = await results.GetFilesAsync();
sortedFiles.ToList<StorageFile>();
foreach (StorageFile item in sortedFiles)
{
StorageFile copiedFile = await item.CopyAsync(mainFolder, item.DisplayName, NameCollisionOption.ReplaceExisting);
}
}
}
}
这种作品 . 当我调用更新方法时,文件复制但不替换,即使我有 CreateFileAsync
的 CreationCollisionOption.ReplaceExisting
选项 . 缩略图也不能识别它是什么类型的文件 . 这是一个截图 . Destination Folder我认为这是由于列表是只读的所以我尝试将其显式转换为列表但我收到了相同的结果 . 我太近了,我只需要一些帮助 . 任何和所有的帮助将不胜感激 .