Sharing and receiving content (HTML)
[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]
Users often come across information they’re excited to share with someone or use in another app. Share is a lightweight, in-context feature that's easy to add to your app.
An app can support the Share feature in two ways. First, it can be a source app that provides content that the user wants to share. Second, the app can be a target app that the user selects as the destination for shared content. An app can also be both a source app and a target app. If you want your app to share content as a source app, you need to decide what data formats your app can provide. We recommend that you try to support as many data formats as possible, but in the end you should choose the ones that make the most sense for your app. After you make that decision, use the classes from the Windows.ApplicationModel.DataTransfer namespace to package up the data.
If you want your app to receive shared content as a target app, you need to first configure your app's manifest file to indicate that it supports the Share contract.
App users can share content from your app with a single swipe from the Share charm. A user can share a file or URL from your app with a different device using Tap and send on the Devices charm.
The Charms bar does not exist on Windows Phone 8.1, so sharing options must be programmatically included by the developer as part of an app bar or other control.
This Share contract allows your app to be presented as an option when the user invokes Share in scenarios in which supported data formats are shared. When choosing data formats for your target app to support, you should register only for the formats that your app can handle. For more guidance, see Choosing data formats. When the user invokes the Share option, only target apps that support the data being shared appear.
If you're using Visual Studio, to add the Share contract to your app, on the Project menu, click Add New Item, and then select Share Target Contract from the list. As part of this process, you need to specify the list of data formats and file types your app can accept. You specify the formats in the Declarations tab while editing the package.appxmanifest file in Visual Studio.
To see an example of how to share content, check out our Sharing content source app sample and Sharing content target app sample, or read through our Quickstart: Sharing content and Quickstart: Receiving shared content topics.
The following diagram is a high-level view of how sharing works.
QuickLinks are not supported on Windows Phone 8.1. If a target app returns a QuickLink, the source app will automatically ignore it.
You can specify the form that opens when the app is activated through the Share contract. This way, you can create a customized experience specifically for sharing. You can find more information about this and other design considerations in Guidelines and checklist for sharing content.
If you are implementing a target app, consider the UI experience. On Windows, when the user selects your app, it will be displayed using the Share flyout. This view state is one of several ways that an app can be displayed on the screen. Make sure your app presents a clean, uncluttered interface for sharing content in the Share flyout.
The content your app receives from a source app cannot be modified. You can, however, let the system know that your app received the data and indicate when it's been processed. This is important, especially for content such as pictures, which might take a while to process and upload. Our Sharing content target app sample shows how this works, or check out our Quickstart: Receiving shared content for more details.
Keep in mind that while these roles—source and target—are different, you can support both within a single app. For example, a photo sharing app might want to act as a source app so users can email their photos to others, and also act as a target app so users can update photo albums with new pictures.
To get started adding Share to your app, check out the following topics and sample apps:
- Guidelines and checklist for sharing content. Whether you're writing a source or a target app, this topic provides useful information that can help you provide the best user experience possible for sharing content.
- Choosing data formats for sharing. Learn about the standard formats for share, and how to create and use custom formats when the standard formats don't apply.
- Sharing content. Here you'll learn the basics of how to implement a source app. We also cover more specific scenarios and provide a few details you should consider during implementation.
- Receiving shared content. The topics here describe how to add the Share contract to your app, the basics of how to detect if a user selects your app to share content with, and how to process the data being shared. We also describe a few specific scenarios to help you get up and running quickly.
- Sharing content source app sample. This sample shows how to initiate a share operation and package content for sharing.
- Sharing content target app sample. This sample shows how to receive content shared from another app.
- Guidelines for debugging target apps. Learn about the issues involved in debugging a Share target app.