1
votes

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.

2

2 Answers

0
votes

Each application is sandboxed. That is isolated storage is the memory allocated for each application to store its app related data. Other applications cannot access those data stored in isolated storage. And the saving and retriveing data files from iso storage is done slightly diffrent way than a file explorer. Such access possible if you save your image files to media libray.

Launchers and Choosers are options provided for such purposes.

1
votes

You cannot share from your isolated storage, since access to it is limited to your app only. In your case, you should first save your pictures to the media library (unless they're saved there automatically), and then you should use media library's path, rather than your own. A case very similar to yours is described here in MSDN.