Edi Wang
Edi Wang

Reputation: 3637

Windows Phone 8: Share an Image from Assets folder

I want to use ShareMediaTask to share an images inside my application's Assets folder, here's the code I use:

private async void MenuShare_Click(object sender, EventArgs e)
{
    StorageFolder installationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
    StorageFile file = await installationFolder.GetFileAsync(@"Assets\shanghaimetro-1.png");

    var shareMediaTask = new ShareMediaTask
    {
        FilePath = file.Path
    };
    shareMediaTask.Show();
}

But the standard Windows Phone sharing screen never appers. It just go back to the page where I came after click the share button.

In debug mode, I am able to see the file.Path is:

C:\Data\Programs\{E6357D2C-2888-448E-8990-4C8D37510514}\Install\Assets\shanghaimetro-1.png

It should be correct path.

Is there anything wrong in this code? How can I make it working?

Upvotes: 2

Views: 574

Answers (1)

Ku6opr
Ku6opr

Reputation: 8126

You need to save the photo to the MediaLibrary and then use the GetPath() extension method (Microsoft.Xna.Framework.Media.PhoneExtensions namespace) to retrieve the path. Assign this path to the FilePath property

Upvotes: 3

Related Questions