我正在尝试使用以下方法选择一个文件:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
try
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the picked file
txt.Text = "Picked file: " + file.Name;
}
else
{
txt.Text = "Operation cancelled.";
}
}
catch (Exception exception)
{
txt.Text = exception.Message;
}
}
...但它抛出一个异常:`指定的方法不受支持。";
我从 Windows Phone 8 文档中复制并粘贴了代码。他们的样品都不起作用。我想也许我缺少文档功能/合同或其他任何东西,但它们甚至不存在于 VS for Phone 应用程序中。
为什么这行不通?
我已将其追踪到尝试的第一行:
FileOpenPicker openPicker = new FileOpenPicker(); // this is the line the exception is thrown on.