Daniel Ballinger
Daniel Ballinger

Reputation: 13537

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?

Upvotes: 3

Views: 1864

Answers (1)

Daniel Ballinger
Daniel Ballinger

Reputation: 13537

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.

Upvotes: 2

Related Questions