Data​Package Data​Package Data​Package Class

Definition

Contains the data that a user wants to exchange with another app.

public : sealed class DataPackage : IDataPackage, IDataPackage2, IDataPackage3public sealed class DataPackage : IDataPackage, IDataPackage2, IDataPackage3Public NotInheritable Class DataPackage Implements IDataPackage, IDataPackage2, IDataPackage3
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

//To see this code in action, add a call to ShareSouceLoad to your constructor or other
//initializing function.
private void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

private void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share Text Example";
    request.Data.Properties.Description = "An example of how to share text.";
    request.Data.SetText("Hello World!");
}
function registerForShare() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", shareTextHandler);
}

function shareTextHandler(e) {
    var request = e.request;
    request.data.properties.title = "Share Text Example";
    request.data.properties.description = "A demonstration that shows how to share.";
    request.data.setText("Hello World!");
}

Remarks

During a share operation, the source app puts the data being shared in a DataPackage object and sends that object to the target app for processing. The DataPackage class includes a number of methods to support the following default formats: text, Rtf, Html, Bitmap, and StorageItems. It also has methods to support custom data formats. To use these formats, both the source app and target app must already be aware that the custom format exists.

Source apps have the option of using SetDataProvider to assign a delegate to a DataPackage, instead of providing the data immediately. This process is useful when the source app supports a given format but does not want to generate the data unless the target app requests the data. For example, a source app might support a variety of image formats for sharing photos. Instead of creating multiple copies of each image using these formats, the source app can use a delegate that is called when the target app requests a specific format type.

Target apps can use the DataPackageView object to acquire the data being shared. In addition, these apps can use the AvailableFormats property to identify which formats the DataPackageView supports, or use the Contains method to query for a specific format.

Windows Phone 8

This API is supported in native apps only.

Constructors

DataPackage() DataPackage() DataPackage()

Constructor that creates a new DataPackage.

public : DataPackage()public DataPackage()Public Sub New()
Attributes

Remarks

In general, the system handles the destruction of a DataPackage object. Your app should not have to handle this event.

Properties

Properties Properties Properties

Allows you to get and set properties like the title of the content being shared.

public : DataPackagePropertySet Properties { get; }public DataPackagePropertySet Properties { get; }Public ReadOnly Property Properties As DataPackagePropertySet
Value
DataPackagePropertySet DataPackagePropertySet DataPackagePropertySet

A collection of properties that describe the data contained in a DataPackage.

Attributes

Remarks

In addition to the content being shared, each instance of a DataPackage object supports a set of properties. Target apps can use these properties to learn more about the content of the DataPackage. Examples of common properties include thumbnail images, title, and file types.

This property contains an instance of the DataPackagePropertySet class. This class supports several properties by default. This class also supports custom properties through its Insert and Lookup methods.

RequestedOperation RequestedOperation RequestedOperation

Specifies the DataPackageOperation (none, move, copy, or link) for the operation.

public : DataPackageOperation RequestedOperation { get; set; }public DataPackageOperation RequestedOperation { get; set; }Public ReadWrite Property RequestedOperation As DataPackageOperation
Value
DataPackageOperation DataPackageOperation DataPackageOperation

The operation requested by the source app.

Attributes

Examples

// Request a copy operation 
datapackage.RequestedOperation = DataPackageOperation.Copy;

// find what the requested operation is
DataPackageOperation operation = dataPackageView.RequestedOperation;
// find out what the requested operation is
var operation = dataPackage.requestedOperation;

// Request a copy operation from targets that support different file operations, like Windows Explorer
dataPackage.requestedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.copy;

Remarks

This property specifies the operation the consumer of a data package should perform in clipboard or drag and drop scenarios. The supported options are specified in the DataPackageOperation enumeration.

When implementing clipboard functionality, DataPackageOperation.Move corresponds to the "Cut" command and DataPackageOperation.Copy to "Copy" command. It is the target of the operation's responsibility to respect this value and report that they performed a cut or copy by calling DataPackageView.ReportOperationComplete with the appropriate value.

In drag and drop scenarios, CoreDragOperation.AllowedOperations should specify the complete set of operations the source allows, and DataPackage.RequestedOperation should specify the source's desired default. Users can override this choices by using SHIFT and CTRL keys. Target apps must inspect the key state to determine the operation the user has selected.

Note

CoreDragOperation.AllowedOperations is not supported in XAML. To specify more than one allowed operation in XAML, pass multiple flags to the DataPackage.RequestedOperation property instead. If you do, you should not set CoreDragOperation.AllowedOperations elsewhere. Doing so will throw an exception and reset the specified flags of DataPackage.RequestedOperation to one.

Normally, DataPackage.RequestedOperation property should specify only a single operation. However, in some interop scenarios (such as copying between a Universal Windows Platform (UWP) app and File Explorer), it can contain more. In this case, the target app should select the best operation (assuming keyboard modifiers have not overridden that choice).

You do not need this property for sharing operations.

See Also

ResourceMap ResourceMap ResourceMap

Maps a URI to a file. Used to ensure that referenced content (such as an image) in HTML content is added to the DataPackage.

public : IMap<string, RandomAccessStreamReference> ResourceMap { get; }public IDictionary<string, RandomAccessStreamReference> ResourceMap { get; }Public ReadOnly Property ResourceMap As IDictionary<string, RandomAccessStreamReference>
Value
IMap<PlatForm::String, RandomAccessStreamReference> IDictionary<string, RandomAccessStreamReference> IDictionary<string, RandomAccessStreamReference>

Specifies a name/value pair that specifies the an HTML path with a corresponding StreamReference object.

Attributes

Examples

public void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

async void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    string htmlExample = "<p>Here is our store logo: <img src='assets/logo.png'>.</p>";
    string fileExample = "assets\\logo.png";
    RandomAccessStreamReference streamRef = null;
    Windows.Storage.StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileExample);
    try
    {
        streamRef = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(file);
    }
    catch (Exception ex)
    {
        // TODO: Handle the exception.
    }
    string htmlFormat = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat(htmlExample);
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share HTML Example";
    request.Data.Properties.Description = "An example of how to share HTML.";
    request.Data.SetHtmlFormat(htmlFormat);
    request.Data.ResourceMap[fileExample] = streamRef;
}
function shareHtmlHandler(e) {
    var request = e.request;
    var htmlExample = "<p>Here is our store logo: <img src='images/logo.png'>.</p>";
    var localImage = "images\\logo.png";
    request.data.properties.title = "Share Html Example";
    request.data.properties.description = "A demonstration that shows how to share an HTML fragment with a local image.";
    var deferral = e.request.getDeferral();
    Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(localImage).done(function (imageFile) {
        request.data.setHtmlFormat(Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.createHtmlFormat(htmlExample));
        request.data.resourceMap[localImage] = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
        deferral.complete();
    }, function (err) {
        request.failWithDisplayText(err);
    });
}

Remarks

HTML content often contains references to other files. The most common example is an img tag that refers to a specific file. To ensure that the image is sent with the rest of the HTML content, you need to use ResourceMap, which maps the URI string to the actual data. You can learn more about this in How to share HTML.

Methods

GetView() GetView() GetView()

Returns a DataPackageView object. This object is a read-only copy of the DataPackage object.

public : DataPackageView GetView()public DataPackageView GetView()Public Function GetView() As DataPackageView
Returns

The object that is a read-only copy of the DataPackage object.

Attributes

SetApplicationLink(Uri) SetApplicationLink(Uri) SetApplicationLink(Uri)

Sets the application link that a DataPackage contains.

public : void SetApplicationLink(Uri value)public void SetApplicationLink(Uri value)Public Function SetApplicationLink(value As Uri) As void
Parameters
value
Uri Uri Uri

A Uniform Resource Identifier (URI) with a scheme that isn't http or https that's handled by the source app.

Attributes

Remarks

Whenever possible, you should set this property. This Uniform Resource Identifier (URI) represents a deep link that takes the user back to the currently displayed content. A source app provides a value for this property, and a target app reads the value. Use this property to indicate the source of the shared content.

The scheme of this Uniform Resource Identifier (URI) must not be http or https. The app sharing this Uniform Resource Identifier (URI) must be capable of being the default handler, although it may not be set as the default handler.

SetBitmap(RandomAccessStreamReference) SetBitmap(RandomAccessStreamReference) SetBitmap(RandomAccessStreamReference)

Sets the bitmap image contained in the DataPackage.

public : void SetBitmap(RandomAccessStreamReference value)public void SetBitmap(RandomAccessStreamReference value)Public Function SetBitmap(value As RandomAccessStreamReference) As void
Parameters
Attributes

Examples

The following example uses the setBitmap method to share an image with a target app.

void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    DataRequestDeferral deferral = e.Request.GetDeferral();
    e.Request.Data.Properties.Title = "Hello World!";
    e.Request.Data.Properties.Description = "This example shows how to share files and images.";
    if (this.dataPackageThumbnail != null)
    {
        e.Request.Data.Properties.Thumbnail = this.dataPackageThumbnail;
    }
    e.Request.Data.SetBitmap(imageStreamRef);
    deferral.Complete();
}
function registerForShare() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", shareImageHandler);
}

function shareImageHandler(e) {
    var request = e.request;
    request.data.properties.title = "Share Image Example";
    request.data.properties.description = "A demonstration that shows how to share an image.";
    var deferral = request.getDeferral();
    Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("images\\smalllogo.png").then(function (thumbnailFile) {
        request.data.properties.thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(thumbnailFile);
        return Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("images\\logo.png");
    }).done(function (imageFile) {
        request.data.setBitmap(Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile));
        deferral.complete();
    }, function (err) {
        request.failWithDisplayText(err);
    });
}

Remarks

This method sets the value for StandardFormats.Bitmap.

Bitmap is one of the data types that the DataPackage object supports directly. See the StandardDataFormats class for information on other supported data types.

SetData(String, Object) SetData(String, Object) SetData(String, Object)

Sets the data contained in the DataPackage in a RandomAccessStream format.

public : void SetData(PlatForm::String formatId, PlatForm::Object value)public void SetData(String formatId, Object value)Public Function SetData(formatId As String, value As Object) As void
Parameters
formatId
PlatForm::String String String

Specifies the format of the data. We recommend that you set this value by using the StandardDataFormats class.

value
PlatForm::Object Object Object

Specifies the content that the DataPackage contains.

Attributes

Remarks

To add data using this method, your app must convert the data into an object. You must also specify a formatId that target apps can use to request the data. Note that the target app can request this data only if it knows the formatId.

This method is often used when you use a delegate function to share data. For more information, see How to support pull operations.

SetDataProvider(String, DataProviderHandler) SetDataProvider(String, DataProviderHandler) SetDataProvider(String, DataProviderHandler)

Sets a delegate to handle requests from the target app.

public : void SetDataProvider(PlatForm::String formatId, DataProviderHandler delayRenderer)public void SetDataProvider(String formatId, DataProviderHandler delayRenderer)Public Function SetDataProvider(formatId As String, delayRenderer As DataProviderHandler) As void
Parameters
formatId
PlatForm::String String String

Specifies the format of the data. We recommend that you set this value by using the StandardDataFormats class.

delayRenderer
DataProviderHandler DataProviderHandler DataProviderHandler

A delegate that is responsible for processing requests from a target app.

Attributes

Examples

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
using Windows.ApplicationModel.DataTransfer;
using Windows.Graphics.Imaging;

namespace ShareMainBetaCS
{
    public sealed partial class ShareFiles : Page
    {
        private StorageFile imageFile = null;
        private RandomAccessStreamReference imageStreamRef = null;
        private RandomAccessStreamReference dataPackageThumbnail = null;
        private IRandomAccessStream imageStream = null;

        public ShareFiles()
        {
            this.InitializeComponent();
            pickImageButton.Click += new RoutedEventHandler(pickImageButton_Click);
            this.ShareSourceLoad();
        }



        async void pickImageButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker imagePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
            };

            this.imageFile = await imagePicker.PickSingleFileAsync();

            if (this.imageFile != null)
            {
                this.imageStreamRef = RandomAccessStreamReference.CreateFromFile(this.imageFile);
                this.dataPackageThumbnail = this.imageStreamRef;
                this.imageStream = await this.imageFile.OpenAsync(FileAccessMode.Read);
            }

        }

        public void ShareSourceLoad()
        {
            DataTransferManager datatransferManager;
            datatransferManager = DataTransferManager.GetForCurrentView();
            datatransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
        }

        void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
        {
            e.Request.Data.Properties.Title = "Hello World!";
            e.Request.Data.Properties.Description = "This example shows how to use delayed sharing.";
            if (this.dataPackageThumbnail != null)
            {
                e.Request.Data.Properties.Thumbnail = this.dataPackageThumbnail;
            }
            e.Request.Data.SetDataProvider(StandardDataFormats.Bitmap, 
                    new DataProviderHandler(this.OnDeferredImageRequestedHandler));

        }
        async void OnDeferredImageRequestedHandler(DataProviderRequest request)
        {
            // Here we provide updated Bitmap data using delayed rendering
            if (this.imageStream != null)
            {
                DataProviderDeferral deferral = request.GetDeferral();

                try
                {
                    InMemoryRandomAccessStream inMemoryStream = new InMemoryRandomAccessStream();

                    // Decode the image
                    BitmapDecoder imageDecoder = await BitmapDecoder.CreateAsync(this.imageStream);

                    // Re-encode the image at 50% width and height
                    BitmapEncoder imageEncoder = await BitmapEncoder.CreateForTranscodingAsync(inMemoryStream, imageDecoder);
                    imageEncoder.BitmapTransform.ScaledWidth = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
                    imageEncoder.BitmapTransform.ScaledHeight = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
                    await imageEncoder.FlushAsync();

                    request.SetData(RandomAccessStreamReference.CreateFromStream(inMemoryStream));
                }

                catch (Exception ex)
                {
                    // Handle the exception
                }

                finally
                {
                    deferral.Complete();
                }
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
    }
}
var imageFile;
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.fileTypeFilter.replaceAll([".jpg", ".bmp", ".gif", ".png", ".wmv"]);
picker.pickSingleFileAsync().then(function (file) {
    logText("PickImage: Picker returned a file");
    imageFile = file;
});

function onDeferredImageRequested(request) {
    try {
        if (imageFile) {
            // This is to make sure deferral works even in synchronous case
            var deferral = request.getDeferral();
            var imageStreamRef = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
            request.setData(imageStreamRef);
            deferral.complete();
        }
    } catch (exc) {
        // Error handling goes here.
    }
}


function shareFiles() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", function (e) {
        var request = e.request;
        request.data.properties.title = "Share Files Example";
        request.data.properties.description = "A demonstration that shows how to share files.";
        request.data.properties.fileTypes.replaceAll([".jpg", ".bmp", ".gif", ".png", ".wmv"]);
        request.data.setDataProvider(Windows.ApplicationModel.DataTransfer.StandardDataFormats.bitmap, onDeferredImageRequested);
    });
}

Remarks

Use the SetDataProvider method when your app supports a specific format, but does not want to supply the data until the target app requests it. We encourage you to use this method if your app shares content that can require significant processing time; for example, sharing a selection of photos, videos, or files.

When you use this method, you need to specify a format and a function. You can specify the format by using the StandardDataFormats class, or you can use a string value for a custom format. The function must put data in the DataPackage by using a method like SetData.

You must specify the extension of the StorageItems being passed to the Share Target.

The SetDataProvider method is different from the GetDeferral method of the DataRequest class. With GetDeferral, a source app can call a function that immediately puts the data in the DataPackage object. The SetDataProvider method is for more complex share operations where packaging the data to be shared is more time-intensive or resource-intensive.

SetHtmlFormat(String) SetHtmlFormat(String) SetHtmlFormat(String)

Adds HTML content to the DataPackage.

public : void SetHtmlFormat(PlatForm::String value)public void SetHtmlFormat(String value)Public Function SetHtmlFormat(value As String) As void
Parameters
value
PlatForm::String String String

The HTML content.

Attributes

Examples

public void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

async void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    string htmlExample = "<p>Here is our store logo: <img src='assets/logo.png'>.</p>";
    string fileExample = "assets\\logo.png";
    RandomAccessStreamReference streamRef = null;
    Windows.Storage.StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileExample);
    try
    {
        streamRef = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(file);
    }
    catch (Exception ex)
    {
        // TODO: Handle the exception.
    }
    string htmlFormat = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat(htmlExample);
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share HTML Example";
    request.Data.Properties.Description = "An example of how to share HTML.";
    request.Data.SetHtmlFormat(htmlFormat);
    request.Data.ResourceMap[fileExample] = streamRef;
}
function shareHtmlHandler(e) {
    var request = e.request;
    var htmlExample = "<p>Here is our store logo: <img src='images/logo.png'>.</p>";
    var localImage = "images\\logo.png";
    request.data.properties.title = "Share Html Example";
    request.data.properties.description = "A demonstration that shows how to share an HTML fragment with a local image.";
    var deferral = e.request.getDeferral();
    Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(localImage).done(function (imageFile) {
        request.data.setHtmlFormat(Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.createHtmlFormat(htmlExample));
        request.data.resourceMap[localImage] = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
        deferral.complete();
    }, function (err) {
        request.failWithDisplayText(err);
    });
}

Remarks

To ensure that a target app can process the HTML content, use HtmlFormatHelper.CreateHtmlFormat. It adds the required headers and other information the string containing the HTML.

If your app supports selection or copying/pasting of HTML content that contains img elements, be sure that the src attributes specify fully-qualified absolute paths to the images, not relative paths.

SetRtf(String) SetRtf(String) SetRtf(String)

Sets the Rich Text Format (RTF) content that is contained in a DataPackage.

public : void SetRtf(PlatForm::String value)public void SetRtf(String value)Public Function SetRtf(value As String) As void
Parameters
value
PlatForm::String String String

Specifies the Rich Text Format (RTF) content for the DataPackage.

Attributes

Remarks

This method sets the value for StandardFormats.Rtf.

Rich Text Format (RTF) is one of the data types that the DataPackage object supports directly. See the StandardDataFormats class for info on other supported data types.

SetStorageItems(IIterable<IStorageItem>) SetStorageItems(IIterable<IStorageItem>) SetStorageItems(IIterable<IStorageItem>)

Sets the files and folders contained in a DataPackage.

public : void SetStorageItems(IIterable<IStorageItem> value)public void SetStorageItems(IEnumerable<IStorageItem> value)Public Function SetStorageItems(value As IEnumerable<IStorageItem>) As void
Parameters
value
IIterable<IStorageItem> IEnumerable<IStorageItem> IEnumerable<IStorageItem>

The files and folders to be added to the DataPackage.

Attributes
See Also

SetStorageItems(IIterable<IStorageItem>, Boolean) SetStorageItems(IIterable<IStorageItem>, Boolean) SetStorageItems(IIterable<IStorageItem>, Boolean)

Adds files and folders to a DataPackage.

public : void SetStorageItems(IIterable<IStorageItem> value, bool readOnly)public void SetStorageItems(IEnumerable<IStorageItem> value, Boolean readOnly)Public Function SetStorageItems(value As IEnumerable<IStorageItem>, readOnly As Boolean) As void
Parameters
value
IIterable<IStorageItem> IEnumerable<IStorageItem> IEnumerable<IStorageItem>

The files and folders to be added to the DataPackage.

readOnly
bool Boolean Boolean

Specify true if the files are read-only; false otherwise.

Attributes
See Also

SetText(String) SetText(String) SetText(String)

Sets the text that a DataPackage contains.

public : void SetText(PlatForm::String value)public void SetText(String value)Public Function SetText(value As String) As void
Parameters
value
PlatForm::String String String

The text.

Attributes

Examples

//To see this code in action, add a call to ShareSouceLoad to your constructor or other
//initializing function.
private void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

private void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share Text Example";
    request.Data.Properties.Description = "An example of how to share text.";
    request.Data.SetText("Hello World!");
}
function registerForShare() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", shareTextHandler);
}

function shareTextHandler(e) {
    var request = e.request;
    request.data.properties.title = "Share Text Example";
    request.data.properties.description = "A demonstration that shows how to share.";
    request.data.setText("Hello World!");
}

Remarks

This method sets the text value for StandardDataFormats.Text. It's the equivalent of calling dataPackage.setText(StandardDataFormats.Text).

Text is one of the data types that the DataPackage object supports directly. See the StandardDataFormats class for information on other supported data types.

SetUri(Uri) SetUri(Uri) SetUri(Uri)

Note

SetUri may be altered or unavailable for releases after Windows 8.1. Instead, use ApplicationLink or WebLink.

Sets the Uniform Resource Identifier (URI) that is contained in the DataPackage.

public : void SetUri(Uri value)public void SetUri(Uri value)Public Function SetUri(value As Uri) As void
Parameters
value
Uri Uri Uri

The Uniform Resource Identifier (URI) that is contained in the DataPackage.

Attributes

Examples

The following code sample demonstrates how an app can set the URI on a DataPackage object.

public void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share Link Example";
    request.Data.Properties.Description = "An example of how to share a link.";
    var link = new Uri("http://www.fabrikam.com");
    request.Data.SetUri(link);
}
function registerForShare() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", shareLinkHandler);
}

function shareLinkHandler(e) {
        var request = e.request;
        request.data.properties.title = "Share Link Example";
        request.data.properties.description = "A demonstration that shows how to add a link (URI) to share.";
        request.data.setUri(new Windows.Foundation.Uri("http://www.fabrikam.com"));
}

Remarks

This method sets the value for StandardFormats.Uri.

Uniform Resource Identifier (URI) is one of the data types that the DataPackage object supports directly. See the StandardDataFormats class for information on other supported data types.

SetWebLink(Uri) SetWebLink(Uri) SetWebLink(Uri)

Sets the web link that a DataPackage contains.

public : void SetWebLink(Uri value)public void SetWebLink(Uri value)Public Function SetWebLink(value As Uri) As void
Parameters
value
Uri Uri Uri

A Uniform Resource Identifier (URI) with an http or https scheme that corresponds to the content being displayed to the user.

Attributes

Remarks

Whenever possible, you should set this property. A source app provides a value for this property, and a target app reads the value. Use this property to indicate the source of the shared content.

Events

Destroyed Destroyed Destroyed

Occurs when the DataPackage is destroyed.

public : event TypedEventHandler Destroyedpublic event TypedEventHandler DestroyedPublic Event Destroyed
Attributes

Remarks

In general, the system handles the destruction of a DataPackage object. Your app should not have to handle this event.

OperationCompleted OperationCompleted OperationCompleted

Occurs when a paste operation is completed.

public : event TypedEventHandler OperationCompletedpublic event TypedEventHandler OperationCompletedPublic Event OperationCompleted
Attributes

Remarks

This event occurs when a user or program pastes content from the Clipboard. If your app is using the DataPackage for share operations, you do not have to handle this event.

ShareCompleted ShareCompleted ShareCompleted

An event that is triggered when a share is completed. Shares can be sent to an app, a provider, or a contact.

public : event TypedEventHandler ShareCompletedpublic event TypedEventHandler ShareCompletedPublic Event ShareCompleted
Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

See Also