DataPackageView DataPackageView DataPackageView DataPackageView Class

A read-only version of a DataPackage. Apps that receive shared content get this object when acquiring content.

Syntax

Declaration

public sealed class DataPackageViewpublic sealed class DataPackageViewPublic NotInheritable Class DataPackageViewpublic sealed class DataPackageView

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.

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

Source apps have the option of using the SetDataProvider(String, DataProviderHandler) to assign a delegate to a DataPackage, instead of providing the data immediately. This process is useful in situations where the source app supports a given format but does not want to generate the data unless the target app requests it. 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.

Examples

The following code shows how you can use the DataPackageView to get the text being shared. For this example to work properly, you need to add code that detects if your app was launched in response to a share operation. See our topic, How to receive text to learn more.

var shareOperation = eventObject.detail.shareOperation;
if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
    shareOperation.data.getTextAsync().done(function (text) {
            // To output the text using this example, 
            // you need a div tag with an id of "output" in your HTML file.
            document.getElementById("output").innerText = text;
        }, function (e) {
            displayError("Error retrieving Text format: " + e);
        }
    });
}

Properties summary

Returns the formats the DataPackageView contains.

Gets a DataPackagePropertySetView object, which contains a read-only set of properties for the data in the DataPackageView object.

Gets the requested operation (such as copy or move). Primarily used for Clipboard actions.

Methods summary

Checks to see if the DataPackageView contains a specific data format.

Gets the application link in the DataPackageView object.

Gets the bitmap image contained in the DataPackageView

Gets the data contained in the DataPackageView.

Gets the HTML stored in the DataPackageView object.

Gets the data (such as an image) referenced in HTML content.

Gets the rich text formatted (RTF) content contained in a DataPackageView.

Gets the files and folders stored in a DataPackageView object.

Gets the text in the DataPackageView object.

Gets the text in the DataPackageView object.

Note

GetUriAsync() may be altered or unavailable for releases after Windows 8.1. Instead, use GetApplicationLinkAsync() or GetWebLinkAsync().

Gets the URI contained in the DataPackageView.

Gets the web link in the DataPackageView object.

Informs the system that your app is finished using the DataPackageView object. Primarily used for Clipboard operations.

Requests permission to unlock and access a data package that is secured with a protection policy.

Requests permission to unlock and access a data package that is secured with a protection policy.

Sets the accepted format Id.

Unlocks a data package and assumes an enterprise identity for it.

Properties

  • AvailableFormats
    AvailableFormats
    AvailableFormats
    AvailableFormats

    Returns the formats the DataPackageView contains.

    public IVectorView<string> AvailableFormats { get; }public IVectorView<string> AvailableFormats { get; }Public ReadOnly Property AvailableFormats As IVectorView<string>public IVectorView<string> AvailableFormats { get; }

    Property Value

  • Properties
    Properties
    Properties
    Properties

    Gets a DataPackagePropertySetView object, which contains a read-only set of properties for the data in the DataPackageView object.

    public DataPackagePropertySetView Properties { get; }public DataPackagePropertySetView Properties { get; }Public ReadOnly Property Properties As DataPackagePropertySetViewpublic DataPackagePropertySetView Properties { get; }

    Property Value

  • RequestedOperation
    RequestedOperation
    RequestedOperation
    RequestedOperation

    Gets the requested operation (such as copy or move). Primarily used for Clipboard actions.

    public DataPackageOperation RequestedOperation { get; }public DataPackageOperation RequestedOperation { get; }Public ReadOnly Property RequestedOperation As DataPackageOperationpublic DataPackageOperation RequestedOperation { get; }

    Property Value

Methods

  • Contains(String)
    Contains(String)
    Contains(String)
    Contains(String)

    Checks to see if the DataPackageView contains a specific data format.

    public bool Contains(String formatId)public bool Contains(String formatId)Public Function Contains(formatId As String) As boolpublic bool Contains(String formatId)

    Parameters

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

      The name of the format.

    Returns

    • bool
      bool
      bool
      bool

      True if the DataPackageView contains the format; false otherwise.

  • GetApplicationLinkAsync()
    GetApplicationLinkAsync()
    GetApplicationLinkAsync()
    GetApplicationLinkAsync()

    Gets the application link in the DataPackageView object.

    public IAsyncOperation<Uri> GetApplicationLinkAsync()public IAsyncOperation<Uri> GetApplicationLinkAsync()Public Function GetApplicationLinkAsync() As IAsyncOperation( Of Uri )public IAsyncOperation<Uri> GetApplicationLinkAsync()

    Returns

    • The application link.

  • GetBitmapAsync()
    GetBitmapAsync()
    GetBitmapAsync()
    GetBitmapAsync()

    Gets the bitmap image contained in the DataPackageView

    public IAsyncOperation<RandomAccessStreamReference> GetBitmapAsync()public IAsyncOperation<RandomAccessStreamReference> GetBitmapAsync()Public Function GetBitmapAsync() As IAsyncOperation( Of RandomAccessStreamReference )public IAsyncOperation<RandomAccessStreamReference> GetBitmapAsync()

    Returns

    • A stream containing the bitmap image.

    Remarks

    Examples

    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.bitmap)) {
    
        if (shareOperation.data.properties.thumbnail) {
            shareOperation.data.properties.thumbnail.openReadAsync().then(function (thumbnailStream) {
                var thumbnailBlob = MSApp.createBlobFromRandomAccessStream(thumbnailStream.contentType, thumbnailStream);
                var thumbnailUrl = URL.createObjectURL(thumbnailBlob, false);
                // To display the thumbnail, you need an element with id of "thumbnail"
                // in your HTML page.
                document.getElementById("thumbnail").src = thumbnailUrl;
            });
        }
        shareOperation.data.getBitmapAsync().then(function (streamRef) {
            streamRef.openReadAsync().then(function (bitmapStream) {
                if (bitmapstream) {
                    var blob = MSApp.createBlobFromRandomAccessStream(bitmapStream.contentType, bitmapstream);
                    var imageUrl = URL.createObjectURL(blob, false);
                    // To display the image, you need an element with id of "imageholder"
                    // in your HTML page.
                    document.getElementById("imageholder").src = imageUrl;
                }
            });
         });
    }
    shareOperation.reportCompleted();
    
  • GetDataAsync(String)
    GetDataAsync(String)
    GetDataAsync(String)
    GetDataAsync(String)

    Gets the data contained in the DataPackageView.

    public IAsyncOperation<object> GetDataAsync(String formatId)public IAsyncOperation<object> GetDataAsync(String formatId)Public Function GetDataAsync(formatId As String) As IAsyncOperation( Of object )public IAsyncOperation<object> GetDataAsync(String formatId)

    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.

    Returns

    • The data.

  • GetHtmlFormatAsync()
    GetHtmlFormatAsync()
    GetHtmlFormatAsync()
    GetHtmlFormatAsync()

    Gets the HTML stored in the DataPackageView object.

    public IAsyncOperation<string> GetHtmlFormatAsync()public IAsyncOperation<string> GetHtmlFormatAsync()Public Function GetHtmlFormatAsync() As IAsyncOperation( Of string )public IAsyncOperation<string> GetHtmlFormatAsync()

    Returns

    • The HTML.

    Remarks

    Examples

    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.html)) {
        document.getElementById("htmlContentArea").className = "unhidden";
        
        shareOperation.data.getHtmlFormatAsync().then(function (html) {
            if (html !== null) {
                var htmlFragment = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.getStaticFragment(htmlFormat);
    
                // Set the innerHTML of the ifram to the HTML fragment.
                var iFrame = document.getElementById("htmlContent");
                iFrame.style.display = "";
                iFrame.contentDocument.documentElement.innerHTML = htmlFragment;
            } 
        });
    
        // Loop through any images and use the resourceMap to map each image element's src.
        var images = iFrame.contentDocument.documentElement.getElementsByTagName("img");
        if (images.length > 0) {
            shareOperation.data.getResourceMapAsync().done(function (resourceMap) {
                if (resourceMap.size > 0) {
                    for (var i = 0, len = images.length; i < len; i++) {
                        var streamReference = resourceMap[images[i].getAttribute("src")];
                        if (streamReference) {
                            // Call a helper function to map the image element's src to a corresponding blob URL generated from the streamReference
                            setResourceMapURL(streamReference, images[i]);
                        }
                    }
                }
            });
    }
    //shareOperation.reportCompleted();
    
  • GetResourceMapAsync()
    GetResourceMapAsync()
    GetResourceMapAsync()
    GetResourceMapAsync()

    Gets the data (such as an image) referenced in HTML content.

    public IAsyncOperation<IMapView<string, RandomAccessStreamReference>> GetResourceMapAsync()public IAsyncOperation<IMapView<string, RandomAccessStreamReference>> GetResourceMapAsync()Public Function GetResourceMapAsync() As IAsyncOperation( Of IMapViewstring, RandomAccessStreamReference )public IAsyncOperation<IMapView<string, RandomAccessStreamReference>> GetResourceMapAsync()

    Returns

    • The data referenced in the HTML content.

  • GetRtfAsync()
    GetRtfAsync()
    GetRtfAsync()
    GetRtfAsync()

    Gets the rich text formatted (RTF) content contained in a DataPackageView.

    public IAsyncOperation<string> GetRtfAsync()public IAsyncOperation<string> GetRtfAsync()Public Function GetRtfAsync() As IAsyncOperation( Of string )public IAsyncOperation<string> GetRtfAsync()

    Returns

    • The rich text formatted content for the DataPackage.

  • GetStorageItemsAsync()
    GetStorageItemsAsync()
    GetStorageItemsAsync()
    GetStorageItemsAsync()

    Gets the files and folders stored in a DataPackageView object.

    public IAsyncOperation<IVectorView<IStorageItem>> GetStorageItemsAsync()public IAsyncOperation<IVectorView<IStorageItem>> GetStorageItemsAsync()Public Function GetStorageItemsAsync() As IAsyncOperation( Of IVectorViewIStorageItem )public IAsyncOperation<IVectorView<IStorageItem>> GetStorageItemsAsync()

    Returns

    Remarks

    Examples

    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.storageItems)) {
        shareOperation.reportStarted();
        shareOperation.data.getStorageItemsAsync().then(function (storageItems) {
            var fileList = "";
            for (var i = 0; i < storageItems.size; i++) {
                fileList += storageItems.getAt(i).name;
                if (i < storageItems.size - 1) {
                    fileList += ", ";
                }
            }
            filesDiv = document.createElement("div");
            filesDiv.innerText = fileList;
            document.body.appendChild(filesDiv);
        });
        shareOperation.reportCompleted();
    }
    
  • GetTextAsync()
    GetTextAsync()
    GetTextAsync()
    GetTextAsync()

    Gets the text in the DataPackageView object.

    public IAsyncOperation<string> GetTextAsync()public IAsyncOperation<string> GetTextAsync()Public Function GetTextAsync() As IAsyncOperation( Of string )public IAsyncOperation<string> GetTextAsync()

    Returns

    • The text.

    Remarks

    Examples

    var shareOperation = eventObject.detail.shareOperation;
    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
        shareOperation.data.getTextAsync().done(function (text) {
                // To output the text using this example, 
                // you need a div tag with an id of "output" in your HTML file.
                document.getElementById("output").innerText = text;
            }, function (e) {
                displayError("Error retrieving Text format: " + e);
            }
        });
    }
    
    var shareOperation = eventObject.detail.shareOperation;
    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
        shareOperation.data.getTextAsync().done(function (text) {
                // To output the text using this example, 
                // you need a div tag with an id of "output" in your HTML file.
                document.getElementById("output").innerText = text;
            }, function (e) {
                displayError("Error retrieving Text format: " + e);
            }
        });
    }
    
  • GetTextAsync(String)
    GetTextAsync(String)
    GetTextAsync(String)
    GetTextAsync(String)

    Gets the text in the DataPackageView object.

    public IAsyncOperation<string> GetTextAsync(String formatId)public IAsyncOperation<string> GetTextAsync(String formatId)Public Function GetTextAsync(formatId As String) As IAsyncOperation( Of string )public IAsyncOperation<string> GetTextAsync(String formatId)

    Parameters

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

      A string that represents the data format. Usually Text.

    Returns

    • The text.

  • GetUriAsync()
    GetUriAsync()
    GetUriAsync()
    GetUriAsync()
    Note

    GetUriAsync() may be altered or unavailable for releases after Windows 8.1. Instead, use GetApplicationLinkAsync() or GetWebLinkAsync().

    Gets the URI contained in the DataPackageView.

    public IAsyncOperation<Uri> GetUriAsync()public IAsyncOperation<Uri> GetUriAsync()Public Function GetUriAsync() As IAsyncOperation( Of Uri )public IAsyncOperation<Uri> GetUriAsync()

    Returns

    • The Uri.

    Remarks

    Examples

    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.uri)) {
        shareOperation.data.getUriAsync().then(function (uri) {
            if (uri !== null) {
                // To output the link using this example, 
                // you need a div tag with an id of "output" in your HTML file.
                document.getElementById("output").innerText = uri.absoluteUri;
            }
        });
    }
    shareOperation.reportCompleted();
    
  • GetWebLinkAsync()
    GetWebLinkAsync()
    GetWebLinkAsync()
    GetWebLinkAsync()

    Gets the web link in the DataPackageView object.

    public IAsyncOperation<Uri> GetWebLinkAsync()public IAsyncOperation<Uri> GetWebLinkAsync()Public Function GetWebLinkAsync() As IAsyncOperation( Of Uri )public IAsyncOperation<Uri> GetWebLinkAsync()

    Returns

    • The web link.

  • ReportOperationCompleted(DataPackageOperation)
    ReportOperationCompleted(DataPackageOperation)
    ReportOperationCompleted(DataPackageOperation)
    ReportOperationCompleted(DataPackageOperation)

    Informs the system that your app is finished using the DataPackageView object. Primarily used for Clipboard operations.

    public void ReportOperationCompleted(DataPackageOperation value)public void ReportOperationCompleted(DataPackageOperation value)Public Function ReportOperationCompleted(value As DataPackageOperation) As voidpublic void ReportOperationCompleted(DataPackageOperation value)

    Parameters

  • RequestAccessAsync()
    RequestAccessAsync()
    RequestAccessAsync()
    RequestAccessAsync()

    Requests permission to unlock and access a data package that is secured with a protection policy.

    public IAsyncOperation<ProtectionPolicyEvaluationResult> RequestAccessAsync()public IAsyncOperation<ProtectionPolicyEvaluationResult> RequestAccessAsync()Public Function RequestAccessAsync() As IAsyncOperation( Of ProtectionPolicyEvaluationResult )public IAsyncOperation<ProtectionPolicyEvaluationResult> RequestAccessAsync()

    Returns

    • When this method completes, it returns the results of the protection policy evaluation, which indicates whether or not the data is accessible.

  • RequestAccessAsync(String)
    RequestAccessAsync(String)
    RequestAccessAsync(String)
    RequestAccessAsync(String)

    Requests permission to unlock and access a data package that is secured with a protection policy.

    public IAsyncOperation<ProtectionPolicyEvaluationResult> RequestAccessAsync(String enterpriseId)public IAsyncOperation<ProtectionPolicyEvaluationResult> RequestAccessAsync(String enterpriseId)Public Function RequestAccessAsync(enterpriseId As String) As IAsyncOperation( Of ProtectionPolicyEvaluationResult )public IAsyncOperation<ProtectionPolicyEvaluationResult> RequestAccessAsync(String enterpriseId)

    Parameters

    • enterpriseId
      System.String
      System.String
      System.String
      System.String

      The enterprise Id.

    Returns

    • When this method completes, it returns the results of the protection policy evaluation, which indicates whether or not the data is accessible.

  • SetAcceptedFormatId(String)
    SetAcceptedFormatId(String)
    SetAcceptedFormatId(String)
    SetAcceptedFormatId(String)

    Sets the accepted format Id.

    public void SetAcceptedFormatId(String formatId)public void SetAcceptedFormatId(String formatId)Public Function SetAcceptedFormatId(formatId As String) As voidpublic void SetAcceptedFormatId(String formatId)

    Parameters

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

      The format Id.

  • UnlockAndAssumeEnterpriseIdentity()
    UnlockAndAssumeEnterpriseIdentity()
    UnlockAndAssumeEnterpriseIdentity()
    UnlockAndAssumeEnterpriseIdentity()

    Unlocks a data package and assumes an enterprise identity for it.

    public ProtectionPolicyEvaluationResult UnlockAndAssumeEnterpriseIdentity()public ProtectionPolicyEvaluationResult UnlockAndAssumeEnterpriseIdentity()Public Function UnlockAndAssumeEnterpriseIdentity() As ProtectionPolicyEvaluationResultpublic ProtectionPolicyEvaluationResult UnlockAndAssumeEnterpriseIdentity()

    Returns

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

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

Details

Assembly

Windows.ApplicationModel.DataTransfer.dll