Sharing Image From Windows Phone 8 App


In this article we will learn about the Share Media Task. This task enables the user to share an image from the app itself to various social media and other sharing platforms. It can be a very useful feature for all the files and media based apps. With this API only images can be shared. Let's see how to use it.

Share Media Task

This is a kind of launcher provided by Windows Phone to launch the share screen from an app so that the user can share the media file. The task expects one parameter for its proper working and that is a file path. 

Before using this task we need to include the following namespace:

using Microsoft.Phone.Tasks;

Use the following procedure to use this task.

  1. Create a new instance of the Share Media Task.

    Microsoft.Phone.Tasks.ShareMediaTask smt = newShareMediaTask();

  2. Next is to set the file path property of this task.

    smt.FilePath = path;

  3. Finally, show this task by calling the show method.


Properties that we can set for this task are as follows:

  • File Path

    Sets the path to the media item to be shared. 


The following code demonstrates how to use the Share Media Task for sharing a media from our app. In this demo I'm capturing a photo and then sharing it. To choose an existing photo you can use the photo chooser task.











    FontFamily="{StaticResource PhoneFontFamilyNormal}"

    FontSize="{StaticResource PhoneFontSizeNormal}"

    Foreground="{StaticResource PhoneForegroundBrush}"

    SupportedOrientations="Portrait" Orientation="Portrait"



    <!--LayoutRoot is the root grid where all page content is placed-->

    <Grid x:Name="LayoutRoot" Background="Transparent">


            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>



        <!--TitlePanel contains the name of the application and page title-->

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

            <TextBlock Text="Demo" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>

            <TextBlock  Text="Demo" Margin="9,-7,0,0" FontSize="40" />



        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <StackPanel Orientation="Vertical">

                <Button x:Name="btnShare" Click="btnOpen_Click"  Content="Capture And share Image" HorizontalAlignment="Left" Width="436" Height="641" VerticalAlignment="Bottom" Margin="10,0,0,0"/>





C# Code Behind

using Microsoft.Phone.Controls;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Diagnostics;

using Microsoft.Phone.Tasks;

using System.Windows.Media;


namespace Demo


    public partial class MainPage : PhoneApplicationPage


        // Constructor

        public MainPage()





        private void btnOpen_Click(object sender, RoutedEventArgs e)





        private void startCamera()


            CameraCaptureTask cct = new CameraCaptureTask();

            cct.Completed += cct_Completed;





        void cct_Completed(object sender, PhotoResult e)


            if (e.TaskResult==TaskResult.OK)







        private void shareImage(string path)


            Microsoft.Phone.Tasks.ShareMediaTask smt = new ShareMediaTask();

            smt.FilePath = path; 





The Show method is used to launch the task.