I'm using the MRTK for a hololens app and I need to select a file that the user puts in their document folder. I am trying to access the FileOpenPicker and use the PickSingleFileAsync() function from a button press to get the file and then load that into my app.
The code inside this function is basically what I am doing:
private async void PickAFileButton_Click(object sender, RoutedEventArgs e)
{
// Clear previous returned file name, if it exists, between iterations of this scenario
OutputTextBlock.Text = "";
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
OutputTextBlock.Text = "Picked photo: " + file.Name;
}
else
{
OutputTextBlock.Text = "Operation cancelled.";
}
}
However, when I build and deploy to the Hololens Emulator, when I press the button It runs through the first part of the code just fine but I get an exception on this line
StorageFile file = await openPicker.PickSingleFileAsync();
After extensive research and some frustration I made a very poor and vague post about it here.
In that post I referenced this post which was made 2 years ago and says you can't do this but The Microsoft docs for Hololens say that you can use File pickers, in this case, FileOpenPicker.
I found this post buried in the Windows Mixed Reality Developer Forum that's related but isn't the issue I am having, I still felt it was necessary to include in this post.
I also want to add that I do have a file picker app installed. According to this post on Microsoft Docs if you call FileOpenPicker it will open whatever file picker was first installed on your device.
Also in the MRTK and the Appx that is being generated I am ensuring the permission to "PictureLibrary" capability is enabled.
Any help would be greatly appreciated, I feel I've waited too long to make a more formal post on this topic and I'm hoping to have some answers. Thanks!