我正在创建一个应用程序,该应用程序的一个要求是允许用户通过更改文档文件夹中的文件夹并按更新按钮来更改应用程序可以访问的数据。 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);
}
}
}
}
这种作品。当我调用更新方法时,即使我有CreationCollisionOption.ReplaceExisting
的{{1}}选项,文件也会复制但不会替换。此外,缩略图不会转移,即使它具有相同的内存,计算机也无法识别它是什么类型的文件。这是一个截图。Destination Folder我认为这是由于列表是readonly所以我尝试将其显式转换为列表但我收到了相同的结果。我很亲密,我只需要一些帮助。任何和所有帮助将不胜感激。