OpenFilePicker不工作在Windows Phone 8(指定的方法不支持)不支持、方法、工作、OpenFilePicker

由网友(yī個亽旳褙影)分享简介:我想随便挑使用文件:专用异步无效Button_Click_1(对象发件人,RoutedEventArgs E){尝试{FileOpenPicker openPicker =新FileOpenPicker();openPicker.ViewMode = PickerViewMode.Thumbnail;openPick...

我想随便挑使用文件:

 专用异步无效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):

  微软停止支持WP 8.1系统 不再试图与安卓和苹果竞争

我们目前不支持选择的文件以外的其他照片或   从其他商店的应用程序选择文件。

所以看起来你被卡住了 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):

We do not currently support choosing files other than photos or choosing files from other Store apps.

So it looks like you are stuck with the PhotoChooserTask instead of FileOpenPicker.

阅读全文

相关推荐

最新文章