Here we describe the various ways that Windows Store apps can share and exchange data.
Users today expect to be able to use technology to connect and share with other people. Whether a user wants to share a link with their social network, copy a picture into a report, or upload a file to cloud storage, apps today need to ensure that the data they use is also available for users to share and exchange.
Windows 8 supports several ways for apps to exchange data with other apps. One of these ways, the Share charm, is new to Windows 8, and requires some explanation so you can use it effectively. Another way, the clipboard, is something that most developers (regardless of what platform you write code for) are familiar with. Still, to use the clipboard today you need to consider not just your content, but also the UI for copying and pasting. This is especially true if your app uses touch as a primary way to get user input. And still another way, saving, is something that's also been around for some time, but hasn't been used in this way before.
We've put together some info on these different ways to share and exchange data to help you decide what options make the most sense for your app and for your users. To see these options in action firsthand, jump over to our code gallery and check out the following samples:
- Sharing content source app sample
- Sharing content target app sample
- Clipboard app sample
- Provide files and a save location through a file picker sample
If you already know what method you want to use and just need a hand getting started, these Quickstart topics should help you out:
- Quickstart: Sharing content
- Quickstart: Receiving shared content
- QuickStart: Clipboard basics
- Quickstart: Providing services from a file picker
We also recommend that you take a look at Sharing content, Receiving shared content, Copying and pasting data, and Integrating with file picker contracts. Those sections will give you more in-depth information that you can use as you develop your app.
The Share charm lets users quickly exchange data between apps without having to navigate away from their current app. For example, a user might want to share a webpage with their friends using a social networking app, or save a link in a note-taking app to refer back to later. The Share charm lets users perform these tasks quickly and easily.
The Share charm is available from anywhere in the system, but can be used only in apps that support sharing. It provides quick and easy access to all apps that can receive shared content (that is, apps that participate in the Share Target contract). Consider participating in the Share Target contract if your app has scenarios for receiving content that a user can quickly complete while in the context of another app. Typically, content for these scenarios would include things like a single webpage or a group of user-selected photos.
In most cases, the user launches the Share charm through a simple touch gesture or mouse click. However, as a developer, you also have the option of launching the Share charm programmatically. This option is ideal when it isn't obvious what a user wants to share.
To learn more about adding share to your app, we recommend that you start with Adding share. From there, you'll learn more about how share works, and how to get started.
To learn more about participating in the Share Target contract, see Receiving shared content.
Another sharing feature called Tap and send is available through the Devices charm. Tap and send is automatically included for apps that act as share sources. It uses Near Field Communication (NFC) to share data between people. In particular, tap and send is ideal for sharing links and files with a nearby friend. Tap and send is available only to users who have the correct hardware, and only appears in the Devices charm when the app has something to share. In most cases, the user launches the Devices charm and selects Tap and send through a simple touch gesture or mouse click.
Copy and paste are the classic ways of exchanging data either between two different apps, or within the same app. It's also a familiar set of actions that users have come to rely on as part of their online experience. Initially, copy and paste actions seem very similar to share, so it's tempting to just use one or the other. However, great apps recognize that these are two different features, and can provide very different user experiences.
One advantage the clipboard has over sharing is that it's the only way to move data from Windows Store apps to the desktop, and vice versa. For example, consider a user who's editing an image using a legacy app. Because the app isn't a Windows Store app, the user is in the desktop. Later, the user decides to use the feature of a Windows Store app to further enhance the picture. In this situation, using the Share charm doesn't make sense. Instead, using the familiar copy and paste commands of the clipboard is a more natural and logical solution.
Just about every app should support copy and paste operations to some degree. In many cases, you can support copy and paste actions with little additional coding. For example, copy and paste shares much of the same API as the share feature. So, if you are already writing code to support share actions, you should be able to extend that code to support copy and paste. If you're using Microsoft Visual Studio to develop your app, you'll find that most of the controls that you can use automatically support copy and paste without any additional work on your part.
When you add support for copy and paste, consider how the user can access the commands. In a mouse and keyboard environment, the classic shortcut keys are probably sufficient. If the user is working on a tablet, however, those shortcuts aren't available. Instead, consider using the app bar or a context-sensitive menu to display copy and paste commands. To learn more, have a look at our Guidelines and checklist for clipboard commands.
You can choose to allow other apps to save files directly to your app, creating an additional method for users to shift data from one app to another. In Windows 8, we've modified how users can save files that they want to work with another app. For example, say you're working on a proposal and you want to make it available to your coworkers. When you save the file, you can pick Microsoft OneDrive as the save location for the file. You don't need to keep track of your file because, by saving it to OneDrive, you've informed OneDrive that it should keep track of it for you.
Receiving files that are saved to your app requires that your app participate in the File Save Picker contract. Apps that participate in this contract are hosted in the file picker that is available from apps that provide an entry point for saving files. Consider participating in the File Save Picker contract if users expect your app to be a typical location for saving a file, and they often want to specify a file name, file type, or location for the file. If you're already participating in the File Open Picker contract, adding the File Save Picker contract is a natural extension to what users already expect from your app. To learn more about participating the File Save Picker contract, see Quickstart: Providing services from a file picker.
Letting other apps use your app as a save location for files makes sense when the user is working with files and folders. It's less intuitive when it comes to smaller sets of data, such as a URL or a text selection. In those cases, the Share charm or the copy and paste commands are better options. That said, there are plenty of situations in which it makes sense to support both the Share charm and saving. For example, consider a user who wants to store a file using a cloud-storage service, such as OneDrive. In this situation, both the Share charm and saving are equally valid options. In the end, you need to consider how your user interacts with your app, and support the contracts and features that match user expectations and provide the best overall experience.