问题描述
我想随便挑使用文件:
专用异步无效Button_Click_1(对象发件人,RoutedEventArgs E)
{
尝试
{
FileOpenPicker openPicker =新FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(JPG);
openPicker.FileTypeFilter.Add(JPEG);
openPicker.FileTypeFilter.Add(。PNG);
StorageFile文件=等待openPicker.PickSingleFileAsync();
如果(文件!= NULL)
{
//应用程序现在已经读/写访问拿起文件
txt.Text =捡到的文件:+ file.Name;
}
其他
{
txt.Text =操作被取消。
}
}
赶上(例外的例外)
{
txt.Text = exception.Message;
}
}
...但它抛出一个异常:'不支持指定的方法;
我复制并从Windows Phone 8的文档粘贴在code。没有他们的样品的工作。我想,也许我缺少一个文件的能力/合同或什么,但他们甚至没有在VS中存在手机的应用程序。
为什么不工作的呢?
我已经跟踪它的尝试的第一行:
FileOpenPicker openPicker =新FileOpenPicker(); //这是抛出异常就行了。
据的MSDN,论坛,从我承担的答案是MS的员工(here):
所以看起来你被卡住了 PhotoChooserTask
而不是 FileOpenPicker
。
I am trying to just pick a file using:
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;
}
}
...but It throws an exception: `Specified method is not supported.";
I copied and pasted the code from the Windows Phone 8 docs. None of their samples work. I thought that maybe I am missing a Documents capability/Contract or whatever but they don't even exist in VS for Phone apps.
Why won't this work?
I have tracked it down to the very first line of the try:
FileOpenPicker openPicker = new FileOpenPicker(); // this is the line the exception is thrown on.
According to the MSDN-forums and an answer from what i assume is a MS employee (here):
So it looks like you are stuck with the PhotoChooserTask
instead of FileOpenPicker
.
这篇关于OpenFilePicker不工作在Windows Phone 8(指定的方法不支持)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!