I am using the CameraCaptureTask to capture images and save them to IsolatedStorage. I am then populating a listbox, named recent
on my MainPage with these saved images. I would then like to use the ShareMediaTask to share one of these images. The requirement for ShareMediaTask that I am having issues with, however, is getting the file path of the image from IsolatedStorage. What I am doing is using the listbox's SelectionChanged event handler to determine which image a user has selected to share. Then, on a button click event, I am searching in IsolatedStorage to retrieve the full path of the selected image from the listbox. Even though a full path is shown, the ShareMediaTask never completes.
MainPage.xaml.cs
//The `recent` ListBox's SelectionChanged event
private void recent_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//retrieve the name of the image that was autogenerated by CameraCaptureTask completed event
fileName = capturedPicture.FileName;
//Combine the directory and file name
filePath = Path.Combine(PictureRepository.IsolatedStoragePath, fileName);
}
private void Share()
{
if(fileName != null)
{
var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
//use the path to open the picture file from the isolated storage by using the IsolatedStorageFile.OpenFile method
var fileStream = isoFile.OpenFile(filePath, FileMode.Open, FileAccess.Read);
string name = fileStream.Name;
_shareTask = new ShareMediaTask();
_shareTask.FilePath = name;
_shareTask.Show();
}
}
In the Share()
method which is called via the button click event, the only way I could figure to get the full path of the image in IsolatedStorage is using the IsolatedStorageFile.OpenFile
method which allowed me to access fileStream.Name
. It seems that still does not work.