在编写WP 8.1应用程序时调用FileOpenPicker.PickSingleFileAndContinue时遇到困难。我所做的只是在我的类中的OnLoaded方法中运行以下代码,该方法继承自Page类。
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.List;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".pdf");
openPicker.FileTypeFilter.Add(".PDF");
openPicker.PickSingleFileAndContinue();
在调用PickSingleFileAndContinue()方法之后,总是抛出以下消息的异常:
" System.UnauthorizedAccessException:访问被拒绝。 (例外 HRESULT:0x80070005(E_ACCESSDENIED))\ r \ n at Windows.Storage.Pickers.FileOpenPicker.PickSingleFileAndContinue()
我可能会对代码做错,但在哪里。任何人都对我的任何帮助表示感谢。谢谢。
答案 0 :(得分:5)
来自MSDN的回答:
Your FileOpenPicker code is fine.
The problem is that you can't call it from your page load.
If you delay it a bit or (better) call it in response to user
action then your code snippet will work.
这解决了这个问题。