我正在尝试在documentlibrary中创建一个新文件夹,并使用FileOpenPicker选择多个图像来保存创建文件夹...
错误是:'System.Collections.Generic.IReadOnlyList'不包含'CopyAsync'的定义,并且没有可以找到接受类型'System.Collections.Generic.IReadOnlyList'的第一个参数的扩展方法'CopyAsync' (您是否缺少using指令或程序集引用?)
这是我的代码:
IReadOnlyList<StorageFile> file;
var destinationFolder = await KnownFolders.DocumentsLibrary.CreateFolderAsync("NewFolder", CreationCollisionOption.GenerateUniqueName);
var openpicker = new FileOpenPicker();
openpicker.CommitButtonText = "Upload";
openpicker.FileTypeFilter.Add(".jpg");
openpicker.FileTypeFilter.Add(".jpeg");
openpicker.FileTypeFilter.Add(".png");
openpicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
openpicker.ViewMode = PickerViewMode.List;
file = await openpicker.PickMultipleFilesAsync();
if (destinationFolder != null && file !=null)
{
await file.CopyAsync(destinationFolder);
}
答案 0 :(得分:1)
当您使用PickMultipleFilesAsync时,您会得到一个文件列表而不是一个文件,因此您需要迭代列表以保存每个文件。
var files = await openpicker.PickMultipleFilesAsync();
if (destinationFolder != null && files !=null)
{
foreach(var fileItem in files)
{
await fileItem.CopyAsync(destinationFolder);
}
}