简体   繁体   中英

How to get file path from IsolatedStorage for ShareMediaTask

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM