OpenFilePicker不工作在Windows Phone 8(指定的方法不支持) [英] OpenFilePicker not working on Windows Phone 8 (Specified method is not supported)

查看:129
本文介绍了OpenFilePicker不工作在Windows Phone 8(指定的方法不支持)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想随便挑使用文件:

 专用异步无效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的员工(<一href="http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/7e4492dc-d8f3-4dc5-8055-625352aaa8b6/">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):

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.

这篇关于OpenFilePicker不工作在Windows Phone 8(指定的方法不支持)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆