3
votes

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?

1

1 Answers

2
votes

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.