1

ピッカーから取得した画像ファイルがあります。'me.png'として保存します:

Windows.Storage.ApplicationData.Current.LocalFolder

古いファイルを新しいファイルで上書きしようとするアクションを再度実行すると、アプリがクラッシュします。

    An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

If there is a handler for this exception, the program may be safely continued.

ファイルを上書きするために使用しているコードは次のとおりです。

            await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "me.png", Windows.Storage.NameCollisionOption.ReplaceExisting);

なぜこれが起こっているのか考えていますか?2回目のコード行でクラッシュしています。衝突オプションをGenerateUniqueNameに変更すると、正常に機能するため、ファイルの上書きに問題があるようです。

アップデート:

完全なコード

    localSettings.Values["me_image_path"] = "Asssets/pinkBackground.png";
                 tile.BackgroundImage = localSettings.Values["me_image_path"];

var picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file == null) return;
            await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "me.png", Windows.Storage.NameCollisionOption.ReplaceExisting);

            localSettings.Values["me_image_path"] = "ms-appdata:///local/me.png";
            tile.BackgroundImage = localSettings.Values["me_image_path"];
4

0 に答える 0