Data​Package​View Data​Package​View Data​Package​View Data​Package​View 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// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

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.

Properties

AvailableFormats AvailableFormats AvailableFormats AvailableFormats

Returns the formats the DataPackageView contains.

public : IVectorView<string> AvailableFormats { get; }public IReadOnlyList<string> AvailableFormats { get; }Public ReadOnly Property AvailableFormats As IReadOnlyList<string>// You can use this property in JavaScript.
Value
IVectorView<PlatForm::String> IReadOnlyList<string> IReadOnlyList<string> IReadOnlyList<string>

The formats the DataPackageView contains.

Attributes

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 DataPackagePropertySetView// You can use this property in JavaScript.
Value
DataPackagePropertySetView DataPackagePropertySetView DataPackagePropertySetView DataPackagePropertySetView

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

Attributes

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 DataPackageOperation// You can use this property in JavaScript.
Value
DataPackageOperation DataPackageOperation DataPackageOperation DataPackageOperation

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

Attributes

Methods

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

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

public : PlatForm::Boolean Contains(PlatForm::String formatId)public bool Contains(String formatId)Public Function Contains(formatId As String) As bool// You can use this method in JavaScript.
Parameters
formatId
PlatForm::String String String String

The name of the format.

Returns
PlatForm::Boolean bool bool bool

True if the DataPackageView contains the format; false otherwise.

Attributes

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 )// You can use this method in JavaScript.
Returns
IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri>

The application link.

Attributes

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 )// You can use this method in JavaScript.
Returns
Attributes

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<PlatForm::Object> GetDataAsync(PlatForm::String formatId)public IAsyncOperation<object> GetDataAsync(String formatId)Public Function GetDataAsync(formatId As String) As IAsyncOperation( Of object )// You can use this method in JavaScript.
Parameters
formatId
PlatForm::String String String 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() GetHtmlFormatAsync()

Gets the HTML stored in the DataPackageView object.

public : IAsyncOperation<PlatForm::String> GetHtmlFormatAsync()public IAsyncOperation<string> GetHtmlFormatAsync()Public Function GetHtmlFormatAsync() As IAsyncOperation( Of string )// You can use this method in JavaScript.
Returns

The HTML.

Attributes

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<PlatForm::String, RandomAccessStreamReference>> GetResourceMapAsync()public IAsyncOperation<IReadOnlyDictionary<string, RandomAccessStreamReference>> GetResourceMapAsync()Public Function GetResourceMapAsync() As IAsyncOperation( Of IReadOnlyDictionarystring, RandomAccessStreamReference )// You can use this method in JavaScript.
Returns
IAsyncOperation<IMapView<PlatForm::String, RandomAccessStreamReference>> IAsyncOperation<IReadOnlyDictionary<string, RandomAccessStreamReference>> IAsyncOperation<IReadOnlyDictionary<string, RandomAccessStreamReference>> IAsyncOperation<IReadOnlyDictionary<string, RandomAccessStreamReference>>

The data referenced in the HTML content.

Attributes

GetRtfAsync() GetRtfAsync() GetRtfAsync() GetRtfAsync()

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

public : IAsyncOperation<PlatForm::String> GetRtfAsync()public IAsyncOperation<string> GetRtfAsync()Public Function GetRtfAsync() As IAsyncOperation( Of string )// You can use this method in JavaScript.
Returns

The rich text formatted content for the DataPackage.

Attributes

GetStorageItemsAsync() GetStorageItemsAsync() GetStorageItemsAsync() GetStorageItemsAsync()

Gets the files and folders stored in a DataPackageView object.

public : IAsyncOperation<IVectorView<IStorageItem>> GetStorageItemsAsync()public IAsyncOperation<IReadOnlyList<IStorageItem>> GetStorageItemsAsync()Public Function GetStorageItemsAsync() As IAsyncOperation( Of IReadOnlyListIStorageItem )// You can use this method in JavaScript.
Returns
IAsyncOperation<IVectorView<IStorageItem>> IAsyncOperation<IReadOnlyList<IStorageItem>> IAsyncOperation<IReadOnlyList<IStorageItem>> IAsyncOperation<IReadOnlyList<IStorageItem>>

An array of files and folders stored in a DataPackageView.

Attributes

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<PlatForm::String> GetTextAsync()public IAsyncOperation<string> GetTextAsync()Public Function GetTextAsync() As IAsyncOperation( Of string )// You can use this method in JavaScript.
Returns

The text.

Attributes

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<PlatForm::String> GetTextAsync(PlatForm::String formatId)public IAsyncOperation<string> GetTextAsync(String formatId)Public Function GetTextAsync(formatId As String) As IAsyncOperation( Of string )// You can use this method in JavaScript.
Parameters
formatId
PlatForm::String String String String

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

Returns

The text.

Attributes
See Also

GetUriAsync() 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 )// You can use this method in JavaScript.
Returns
IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri>

The Uri.

Attributes

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 )// You can use this method in JavaScript.
Returns
IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri>

The web link.

Attributes

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 void// You can use this method in JavaScript.
Parameters
value
DataPackageOperation 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() 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 )// You can use this method in JavaScript.
Returns

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

Attributes
See Also

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(PlatForm::String enterpriseId)public IAsyncOperation<ProtectionPolicyEvaluationResult> RequestAccessAsync(String enterpriseId)Public Function RequestAccessAsync(enterpriseId As String) As IAsyncOperation( Of ProtectionPolicyEvaluationResult )// You can use this method in JavaScript.
Parameters
enterpriseId
PlatForm::String String String 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
See Also

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

Sets the accepted format Id.

public : void SetAcceptedFormatId(PlatForm::String formatId)public void SetAcceptedFormatId(String formatId)Public Function SetAcceptedFormatId(formatId As String) As void// You can use this method in JavaScript.
Parameters
formatId
PlatForm::String String String String

The format Id.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

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 ProtectionPolicyEvaluationResult// You can use this method in JavaScript.
Returns

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

Attributes

See Also