Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileOpenPicker PickSingleFileAsync throws UnauthorizedAccessException

The following code is almost verbatim from the MSDN example for the FileOpenPicker class.

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

StorageFile file = await picker.PickSingleFileAsync();

When I trigger it from a button I get the following exception from the last line:

System.UnauthorizedAccessException
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I thought the idea of the FileOpenPicker in this usage was that I didn't need to ask the user for access permissions or specify any capabilities?

like image 640
Daniel Ballinger Avatar asked Dec 07 '25 03:12

Daniel Ballinger


1 Answers

I set a breakpoint just before the call to PickSingleFileAsync(). Turns out that two tapped events were being fired when pressing a TextBlock within a Border (both with the same Tapped event handler).

The first call worked as expected, but subsequent call resulted in the UnauthorizedAccessException and would occur straight after the picker was displayed.

like image 190
Daniel Ballinger Avatar answered Dec 08 '25 17:12

Daniel Ballinger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!