DataPackage DataPackage DataPackage DataPackage Class

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

Syntax

Declaration

public sealed class DataPackagepublic sealed class DataPackagePublic NotInheritable Class DataPackage

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(System.String,Windows.ApplicationModel.DataTransfer.DataProviderHandler) 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(System.String) method to query for a specific format.

Windows Phone 8

This API is supported in native apps only.

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!");
}

Constructors summary

Constructor that creates a new DataPackage.

Properties summary

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

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

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

Methods summary

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

Sets the application link that a DataPackage contains.

Sets the bitmap image contained in the DataPackage.

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

Sets a delegate to handle requests from the target app.

Adds HTML content to the DataPackage.

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

Sets the files and folders contained in a DataPackage.

Adds files and folders to a DataPackage.

Sets the text that a DataPackage contains.

Note

SetUri(Windows.Foundation.Uri) may be altered or unavailable for releases after Windows 8.1. Instead, use SetApplicationLink(Windows.Foundation.Uri) or SetWebLink(Windows.Foundation.Uri).

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

Sets the web link that a DataPackage contains.

Events summary

Occurs when the DataPackage is destroyed.

Occurs when a paste operation is completed.

Constructors

  • DataPackage()
    DataPackage()
    DataPackage()
    DataPackage()

    Constructor that creates a new DataPackage.

    public DataPackage()public DataPackage()Public Function DataPackage() As

    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
    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

    Property Value

    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 FileTypes.

    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(System.String,System.Object) and Lookup(System.String) methods.

  • RequestedOperation
    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

    Property Value

    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 corresponds to the "Cut" command and DataPackageOperation 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 ReportOperationCompleted(Windows.ApplicationModel.DataTransfer.DataPackageOperation) with the appropriate value.

    In drag and drop scenarios, AllowedOperations should specify the complete set of operations the source allows, and 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

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

    Normally, 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.

    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;
    
  • ResourceMap
    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<RandomAccessStreamReference> ResourceMap { get; }public IMap<RandomAccessStreamReference> ResourceMap { get; }Public ReadOnly Property ResourceMap As IMap<RandomAccessStreamReference>

    Property Value

    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.

    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);
        });
    }
    

Methods

  • GetView()
    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

  • SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference)
    SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference)
    SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference)
    SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference)

    Sets the bitmap image contained in the DataPackage.

    public void SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference)public void SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference)Public Function SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference) As void

    Parameters

    Remarks

    This method sets the value for 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.

    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);
        });
    }
    
  • SetData(System.String,System.Object)
    SetData(System.String,System.Object)
    SetData(System.String,System.Object)
    SetData(System.String,System.Object)

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

    public void SetData(System.String,System.Object)public void SetData(System.String,System.Object)Public Function SetData(System.String,System.Object) As void

    Parameters

    • formatId
      System.String
      System.String
      System.String
      System.String

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

    • value
      System.Object
      System.Object
      System.Object
      System.Object

      Specifies the content that the DataPackage contains.

    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(System.String,Windows.ApplicationModel.DataTransfer.DataProviderHandler)
    SetDataProvider(System.String,Windows.ApplicationModel.DataTransfer.DataProviderHandler)
    SetDataProvider(System.String,Windows.ApplicationModel.DataTransfer.DataProviderHandler)
    SetDataProvider(System.String,Windows.ApplicationModel.DataTransfer.DataProviderHandler)

    Sets a delegate to handle requests from the target app.

    public void SetDataProvider(System.String,Windows.ApplicationModel.DataTransfer.DataProviderHandler)public void SetDataProvider(System.String,Windows.ApplicationModel.DataTransfer.DataProviderHandler)Public Function SetDataProvider(System.String,Windows.ApplicationModel.DataTransfer.DataProviderHandler) As void

    Parameters

    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(System.String,System.Object).

    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.

    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);
        });
    }
    
    
  • SetHtmlFormat(System.String)
    SetHtmlFormat(System.String)
    SetHtmlFormat(System.String)
    SetHtmlFormat(System.String)

    Adds HTML content to the DataPackage.

    public void SetHtmlFormat(System.String)public void SetHtmlFormat(System.String)Public Function SetHtmlFormat(System.String) As void

    Parameters

    • value
      System.String
      System.String
      System.String
      System.String

      The HTML content.

    Remarks

    To ensure that a target app can process the HTML content, use CreateHtmlFormat(System.String). 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.

    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);
        });
    }
    
  • SetRtf(System.String)
    SetRtf(System.String)
    SetRtf(System.String)
    SetRtf(System.String)

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

    public void SetRtf(System.String)public void SetRtf(System.String)Public Function SetRtf(System.String) As void

    Parameters

    • value
      System.String
      System.String
      System.String
      System.String

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

    Remarks

    This method sets the value for 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(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem})
    SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem})
    SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem})
    SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem})

    Sets the files and folders contained in a DataPackage.

    public void SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem})public void SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem})Public Function SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem}) As void

    Parameters

    • value

      The files and folders to be added to the DataPackage.

  • SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem},System.Boolean)
    SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem},System.Boolean)
    SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem},System.Boolean)
    SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem},System.Boolean)

    Adds files and folders to a DataPackage.

    public void SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem},System.Boolean)public void SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem},System.Boolean)Public Function SetStorageItems(Windows.Foundation.Collections.IIterable{Windows.Storage.IStorageItem},System.Boolean) As void

    Parameters

    • value

      The files and folders to be added to the DataPackage.

    • readOnly
      System.Boolean
      System.Boolean
      System.Boolean
      System.Boolean

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

  • SetText(System.String)
    SetText(System.String)
    SetText(System.String)
    SetText(System.String)

    Sets the text that a DataPackage contains.

    public void SetText(System.String)public void SetText(System.String)Public Function SetText(System.String) As void

    Parameters

    • value
      System.String
      System.String
      System.String
      System.String

      The text.

    Remarks

    This method sets the text value for 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.

    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!");
    }
    
  • SetUri(Windows.Foundation.Uri)
    SetUri(Windows.Foundation.Uri)
    SetUri(Windows.Foundation.Uri)
    SetUri(Windows.Foundation.Uri)
    Note

    SetUri(Windows.Foundation.Uri) may be altered or unavailable for releases after Windows 8.1. Instead, use SetApplicationLink(Windows.Foundation.Uri) or SetWebLink(Windows.Foundation.Uri).

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

    public void SetUri(Windows.Foundation.Uri)public void SetUri(Windows.Foundation.Uri)Public Function SetUri(Windows.Foundation.Uri) As void

    Parameters

    Remarks

    This method sets the value for 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.

    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"));
    }
    

Events

  • Destroyed
    Destroyed
    Destroyed
    Destroyed

    Occurs when the DataPackage is destroyed.

    public event TypedEventHandler Destroyedpublic event TypedEventHandler DestroyedPublic Event Destroyed

    Remarks

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

  • OperationCompleted
    OperationCompleted
    OperationCompleted
    OperationCompleted

    Occurs when a paste operation is completed.

    public event TypedEventHandler OperationCompletedpublic event TypedEventHandler OperationCompletedPublic Event OperationCompleted

    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.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute

Details

Assembly

Windows.ApplicationModel.DataTransfer.dll