【发布时间】:2013-03-12 09:21:43
【问题描述】:
我正在尝试使用以下方法选择一个文件:
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;
}
}
...但是它会抛出异常:`Specified method is not supported.";
我从 Windows Phone 8 文档中复制并粘贴了代码。他们的样品都不起作用。我想也许我缺少文档功能/合同或其他任何东西,但它们甚至不存在于 VS for Phone 应用程序中。
为什么这不起作用?
我已经追踪到尝试的第一行:
FileOpenPicker openPicker = new FileOpenPicker(); // this is the line the exception is thrown on.
【问题讨论】:
-
使用 AndContinue() 代替 PickSingleFileAsync。有关如何使用它的详细信息,请参阅我的答案。出于对手机内存的考虑,windows Phone 团队需要像这样实现它。同时打开文件选择器应用程序和您的应用程序是不可行的。相反,您的应用会暂停,文件选择器会打开,然后您的应用会恢复。
标签: c# .net xaml windows-phone-8 fileopenpicker