简体   繁体   English

如何从IsolatedStorage获取ShareMediaTask的文件路径

[英]How to get file path from IsolatedStorage for ShareMediaTask

I am using the CameraCaptureTask to capture images and save them to IsolatedStorage. 我正在使用CameraCaptureTask捕获图像并将其保存到IsolatedStorage。 I am then populating a listbox, named recent on my MainPage with these saved images. 然后,我用这些保存的图像填充一个列表框,该列表框在我的主页上名为“ recent ”。 I would then like to use the ShareMediaTask to share one of these images. 然后,我想使用ShareMediaTask共享这些图像之一。 The requirement for ShareMediaTask that I am having issues with, however, is getting the file path of the image from IsolatedStorage. 但是,我遇到问题的ShareMediaTask的要求是从IsolatedStorage获取映像的文件路径。 What I am doing is using the listbox's SelectionChanged event handler to determine which image a user has selected to share. 我正在使用列表框的SelectionChanged事件处理程序来确定用户选择共享的图像。 Then, on a button click event, I am searching in IsolatedStorage to retrieve the full path of the selected image from the listbox. 然后,在按钮单击事件中,我正在IsolatedStorage中搜索,以从列表框中检索所选图像的完整路径。 Even though a full path is shown, the ShareMediaTask never completes. 即使显示了完整路径,ShareMediaTask也永远不会完成。

MainPage.xaml.cs 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 . 在通过按钮click事件调用的Share()方法中,我想知道在IsolatedStorage中获取图像的完整路径的唯一方法是使用IsolatedStorageFile.OpenFile方法,该方法允许我访问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 . 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. 从iso存储中保存和检索数据文件的方式与文件浏览器略有不同。 Such access possible if you save your image files to media libray. 如果将图像文件保存到媒体库,则可以进行这种访问。

Launchers and Choosers are options provided for such purposes. 启动器和选择器是为此目的提供的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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