我现在是一名学生,使用csharp和xaml学习win10应用程序开发,最近当我尝试在我的代码中选择一个图像并稍后替换我本地文件夹中的现有图像时,发生System.UnauthorizedAccessException
。这是非常令人困惑的,因为当我第一次创建它时,我能够在我的本地文件夹中修改图像文件,但是在导航到另一个页面然后再返回到该页面以再次修改它之后,它并没有这样做。工作!有人可以帮我解决这个问题吗?
private async void select_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker picker = new FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
picker.FileTypeFilter.Add(".bmp");
StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
BitmapImage pic = new BitmapImage();
pic.SetSource(stream);
this.head.Source = pic;
StorageFolder storageFolder =
ApplicationData.Current.LocalFolder;
StorageFile sampleFile =
await storageFolder.CreateFileAsync(PlayerName.Text + ".jpg", CreationCollisionOption.ReplaceExisting);
await file.CopyAndReplaceAsync(sampleFile);
//await file.CopyAsync(ApplicationData.Current.LocalFolder, PlayerName.Text + ".jpg", NameCollisionOption.ReplaceExisting);