将视频文件复制到本地文件夹不起作用

时间:2017-12-12 08:32:52

标签: c# uwp uwp-xaml

我想将文件上传到UWP的LocalFolder。它适用于图像。但是对于一些大的mp4文件,它已经存在异常并显示错误

  

“System.Runtime.InteropServices.COMException:错误HRESULT E_FAIL已从调用COM组件返回。”

private async void BtnTestUpload_ClickAsync(object sender, RoutedEventArgs e)
{
    var picker = new Windows.Storage.Pickers.FileOpenPicker();
    picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
    picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
    picker.FileTypeFilter.Add(".jpg");
    picker.FileTypeFilter.Add(".jpeg");
    picker.FileTypeFilter.Add(".png");
    picker.FileTypeFilter.Add(".mp4");

    Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
    if (file != null)
    {
        try
        {
            await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.FailIfExists);
            var dialog = new MessageDialog("Upload Successfull");

            await dialog.ShowAsync();
        }
        catch (Exception ex)
        {
            var dialog = new MessageDialog("fail" + ex.ToString());

            await dialog.ShowAsync();
        }
    }
}

0 个答案:

没有答案