1

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.
SysDragon
  • 9,692
  • 15
  • 60
  • 89
James
  • 167
  • 1
  • 3
  • 11
  • Use AndContinue() instead of PickSingleFileAsync. See my answer for the details on how to use it. The windows Phone team needed to implement it like this because of memory considerations on a phone. Having both a file picker app and your app open at the same time isn't feasible. Instead your app suspends, the file picker opens and then your app resumes. – Lance McCarthy Jun 03 '14 at 17:09

4 Answers4

5

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.

PKeno
  • 2,694
  • 7
  • 20
  • 37
  • I was going to down-vote this simply because I disagree with their decision to not allow us to pick other file types. Lol. But I didn't. +1 - atleast I know, now. – James Mar 13 '13 at 02:29
5

This does work but only for Windows Phone 8.1 (Windows Phone) and not Windows Phone 8.0/8.1 (Windows Phone Silverlight).

Here is the code:

FileOpenPicker singleFilePicker = new FileOpenPicker();
        singleFilePicker.ViewMode = PickerViewMode.Thumbnail;
        singleFilePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        singleFilePicker.FileTypeFilter.Add(".jpg");
        singleFilePicker.FileTypeFilter.Add(".jpeg");
        singleFilePicker.FileTypeFilter.Add(".png");
        singleFilePicker.PickSingleFileAndContinue();

Add this method to handle the chosen photo(s):

public void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
    {
        if (args.Files.Count > 0)
        {
            var userChosenbPhoto = args.Files[0].Name;
        }
        else
        {
            //user canceled picker
        }
    }

You can also grab multiple files, too.

Last but most importantly, you need to add a continuation manager class to your project. This will manage the reactivation of the app when returning from a picker. Go to this documentation to learn how to add a ContinuationManager to the project (sorry for a link, too much info to put here).

Lance McCarthy
  • 1,884
  • 1
  • 20
  • 40
1

You can only use the FileOpenPickerfrom native apps, like the Direct3D ones.

You can use the PhotoChooserTask instead to select a picture from the Pictures Hub.

Pedro Lamas
  • 7,185
  • 4
  • 27
  • 35
0

According to the documentation, it is mentioned that: Minimum supported phone : None supported

Check this link for details http://msdn.microsoft.com/en-us/library/windowsphone/develop/br207852.aspx

Byron Gavras
  • 970
  • 10
  • 16