FileOpenPicker PickSingleFileAsync throws UnauthorizedAccessException

末鹿安然 提交于 2019-12-12 15:38:03

问题


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:


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.



来源:https://stackoverflow.com/questions/15493455/fileopenpicker-picksinglefileasync-throws-unauthorizedaccessexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!