我正在尝试在文档库中创建一个新文件夹并使用 FileOpenPicker 选择一个图像来保存创建文件夹...
我面临的错误是:
mscorlib.dll 中出现“System.Exception”类型的异常,但未在用户代码中处理
附加信息:当该文件已存在时无法创建该文件。(来自 HRESULT 的异常:0x800700B7)
如果有这个异常的处理程序,程序可以安全地继续。
这是我的代码:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
StorageFolder storage = KnownFolders.DocumentsLibrary;
storage = await storage.CreateFolderAsync("New folder", 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.PickSingleFileAsync();
var imageFile = await StorageFile.GetFileFromPathAsync(file.Path);
IRandomAccessStream rStream = await imageFile.OpenAsync(FileAccessMode.ReadWrite);
Stream stream = rStream.AsStreamForWrite();
if (storage != null)
{
if (file != null)
{
await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder);
}
}
}