DataPackageView DataPackageView DataPackageView Class

Definition

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

public sealed class DataPackageView : IDataPackageView, IDataPackageView2, IDataPackageView3, IDataPackageView4public sealed class DataPackageView : IDataPackageView, IDataPackageView2, IDataPackageView3, IDataPackageView4Public NotInheritable Class DataPackageView Implements IDataPackageView, IDataPackageView2, IDataPackageView3, IDataPackageView4
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 method to query for a specific format.

Source apps have the option of using the SetDataProvider 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

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

The formats the DataPackageView contains.

Attributes

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

The object that contains a read-only set of properties for the data.

Attributes

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

An enumeration that states what operation (such as copy or move) was completed.

Attributes

Methods

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 bool
Parameters
formatId
System.String System.String System.String

The name of the format.

Returns
bool bool bool

True if the DataPackageView contains the format; false otherwise.

Attributes

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

The application link.

Attributes

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

A stream containing the bitmap image.

Attributes

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)

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 )
Parameters
formatId
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.

Attributes

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

The HTML.

Attributes

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

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

The data referenced in the HTML content.

Attributes

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

The rich text formatted content for the DataPackage.

Attributes

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

An array of files and folders stored in a DataPackageView.

Attributes

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

Gets the text in the DataPackageView object.

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

The text.

Attributes

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)

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 )
Parameters
formatId
System.String System.String System.String

A string that represents the data format. Usually StandardDataFormats.text.

Returns

The text.

Attributes

GetUriAsync() GetUriAsync() GetUriAsync()

Note

GetUriAsync may be altered or unavailable for releases after Windows 8.1. Instead, use GetApplicationLink or GetWebLink.

Gets the URI contained in the DataPackageView.

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

The Uri.

Attributes

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

Gets the web link in the DataPackageView object.

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

The web link.

Attributes

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 void
Parameters
value
DataPackageOperation DataPackageOperation DataPackageOperation

An enumeration that states what operation (such as copy or move) was completed. At most one operation flag can be set.

Attributes

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

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

Attributes

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 )
Parameters
enterpriseId
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.

Attributes

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 void
Parameters
formatId
System.String System.String System.String

The format Id.

Attributes

UnlockAndAssumeEnterpriseIdentity() UnlockAndAssumeEnterpriseIdentity() UnlockAndAssumeEnterpriseIdentity()

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

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

When this method completes, it returns the results of the protection policy evaluation.

Attributes

See Also