Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 01:02, 5 September 2013 by hamishwillee (Talk | contribs)

Sharing media on Windows Phone 8

From Wiki
Jump to: navigation, search

This article explains how to share images from Windows Phone to multiple destinations including cloud storage services, social networks. We will also utilize Bluetooth and NFC to perform easy sharing locally between different devices.

WP Metro Icon Multimedia.png
Article Metadata
Platform Security
Created: MMlejnek (29 Aug 2013)
Last edited: hamishwillee (05 Sep 2013)



This article will help you implement media sharing in your Windows Phone 8 applications. We will cover multiple different techniques and implement them in a way so that they will be easy to plug in into any app you create.

Built-in sharing

Windows Phone offers a powerful image sharing capability built-in. The main advantages of this default approach is that any app can be plugged in to the sharing list, receive the shared image and then share it forward – on social networks, cloud storage, etc.


First we implement a simple UI – we need only one button to choose the image from the photos library / camera and an application button to share it.

<Grid x:Name="LayoutRoot" Background="Transparent">
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<StackPanel x:Name="TitlePanel" Margin="20">
<TextBlock Text="NOKIA IMAGING WIKI" />
<TextBlock Text="built-in sharing" FontSize="40" />
<Grid x:Name="ContentPanel" Grid.Row="1">
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<Button Click="ChooseImage_Click">Capture / choose image</Button>
<Image x:Name="capturedImage" Grid.Row="1" Margin="30" />
<shell:ApplicationBarIconButton IsEnabled="False"
IconUri="Assets/share.png" Click="Share_Click" Text="share" />

The code-behind is also quite simple. First we need to declare two class-level variables – a PhotoChooserTask and a string variable for image's path.

PhotoChooserTask photoChooser;
string currentMediaPath = null;

In the page's constructor we have to initialize the PhotoChooserTask and then add an event handler for the task's completion.

public BuiltInSharing()
photoChooser = new PhotoChooserTask();
photoChooser.Completed += photoChooser_Completed;

The Choose image button's click handler is very simple – just a call to show the Photo Chooser

private void ChooseImage_Click( object sender, RoutedEventArgs e )

The "photoChooser_Completed" event handler makes a few checks and exception handling after the user selects an image. We display it in the dedicated image UI control and also store it's full file name. This will be used later for sharing.

void photoChooser_Completed( object sender, PhotoResult e )
if ( e.TaskResult == TaskResult.OK )
BitmapImage image = new BitmapImage();
image.SetSource( e.ChosenPhoto );
capturedImage.Source = image;
currentMediaPath = e.OriginalFileName;
( ( ApplicationBarIconButton )ApplicationBar.Buttons[ 0 ] ).IsEnabled = true;
currentMediaPath = null;
( ( ApplicationBarIconButton )ApplicationBar.Buttons[ 0 ] ).IsEnabled = false;
currentMediaPath = null;
( ( ApplicationBarIconButton )ApplicationBar.Buttons[ 0 ] ).IsEnabled = false;

Now we get to the application bar button click handler. We create a ShareMediaTask and let the OS handle the process.

private void Share_Click( object sender, EventArgs e )
if ( currentMediaPath != null )
//we can share
ShareMediaTask task = new ShareMediaTask();
task.FilePath = currentMediaPath;

Disadvantages of ShareMediaTask

As we could see, implementing the ShareMediaTask is very easy and fast. However, it has some disadvantages. Firstly, we don't know which sharing target-capable apps the user has installed so we cannot guarantee that all users will have the same experience. The second major problem is that the ShareMediaTask doesn't support sharing from the app's IsolatedStorage. The reason for this is that the OS would have to give read access to the file in Isolated Storage, which is forbidden. You can overcome this issue by in-memory image rendering using "WriteableBitmap", but this approach is less reliable for larger images and low-memory devices.

Windows Azure Storage


Remove Category:Draft when the page is complete or near complete

The "platform categories" will be displayed here in preview only - Copy paste relevant categories into text here

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

Add categories below using category selector.

309 page views in the last 30 days.