On mobile platforms, where it’s important to move between apps fluidly with somewhat limiting interfaces and partitioned app model, sharing content between apps is very powerful.
Windows Phone’s sharing implementation is great, and you can make your app a share target (allow it to receive content sent from another app) with just a few lines of code.
In this article I’ll demonstrate how to make a very simple app that is a share target for a hyperlink. The app will display the link it receives in a popup box, and then return the user back to the app that shared the link.
Note: this method targets Windows Phone 8.1.
This simple implementation breaks down into two steps:
- Step 1: Enable share target permission
- Step 2: Add the code to receive shared content
Get started
Create a new project for Windows Phone. You can use either C# or Visual Basic to follow along. Visual Studio 2013 (or the Express equivalent) is required.
Step 1: Give your App Share Target Permission
A Windows Phone app must declare it is a share target, and what content it can receive from shares. This is what determines that your app should pop up in the list of targets when a user shares content from another app.
Open Package.appxmanifest and select the Declarations tab, then:
- In the Available Declarations panel on the left, select Share Target from the drop-down
- Click Add
- In the Share Description field enter a name/description (e.g. Media Link)
- Type the content type to receive in the Data format: field. In this example use URI (a hyperlink, such as you would share from Internet Explorer).

Now your app is able to receive shared content from another app.
Step 2: Implement the Code
Add the following method to App.Xaml.cs / App.Xaml.vb. The OnShareTargetActivated method will run whenever you app is launched.
You need first add some using declarations at the top of the class:
C#
using Windows.UI.Popups; using Windows.ApplicationModel.Activation;
VB
Imports Windows.UI.Popups Imports Windows.ApplicationModel.Activation
Next, add in the method that runs when the user chooses the app when sharing:
C#
protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
var link = args.ShareOperation.Data.GetWebLinkAsync().GetResults();
MessageDialog messageDialog = new MessageDialog(link.ToString());
messageDialog.ShowAsync();
args.ShareOperation.ReportCompleted();
}
VB
protected Overrides Sub OnShareTargetActivated(args As ShareTargetActivatedEventArgs)
Dim link = args.ShareOperation.Data.GetWebLinkAsync().GetResults()
Dim messageDialog As New MessageDialog(link.ToString())
messageDialog.ShowAsync()
args.ShareOperation.ReportCompleted()
End Sub
And that’s all you need!
Testing the App
- Deploy your app to your phone (or the simulator)
- Launch Internet Explorer, and navigate to a webpage
- Choose the Share option from the slide-up menu at the bottom of the screen (Note: Share is greyed out until the page finishes loading)
- Select your app as the target.
You should see the popup message appear with the URL that was shared, then you will be returned to Internet Explorer.
Note: If your app doesn’t show up on the share target list, double-check that you’ve allowed the app to be a share target.
How does it work?
Now that you have it working I will explain the code so you can understand what is happening.
OnShareActivated automatically runs when your app is launched as a share target.
Line 1: this extracts the data we want from the shared data bundle (ShareOperation.Data) sent to our app. In this example we knew we could only receive a hyperlink, so we just went and extracted a hyperlink. You can alternately use ShareOperation.Data.Contains() to determine if the data you want is present (e.g. if your app can receive different data types).
Line 2: & 3: Create and display a message dialog to the user with a string extracted from the shared data.
Line 4: This tells the OS that you’ve handled the sharing. Your app window is closed and the user is returned to the originating app.