Reputation: 167
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.
Upvotes: 1
Views: 4230
Reputation: 1917
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).
Upvotes: 5
Reputation: 990
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
Upvotes: 0
Reputation: 2844
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
.
Upvotes: 5
Reputation: 7233
You can only use the FileOpenPicker
from native apps, like the Direct3D ones.
You can use the PhotoChooserTask instead to select a picture from the Pictures Hub.
Upvotes: 1