DataPackageView 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, IDataPackageView4
public sealed class DataPackageView : IDataPackageView, IDataPackageView2, IDataPackageView3, IDataPackageView4
Public NotInheritable Class DataPackageView Implements IDataPackageView, IDataPackageView2, IDataPackageView3, IDataPackageView4
// This class does not provide a public constructor.
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<Platform::String> AvailableFormats { get; }
public IReadOnlyList<string> AvailableFormats { get; }
Public ReadOnly Property AvailableFormats As IReadOnlyList<string>
var iReadOnlyList = dataPackageView.availableFormats;
Value
IVectorView<Platform::String> IReadOnlyList<string> IReadOnlyList<string> IReadOnlyList<string>

The formats the DataPackageView contains.

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
var dataPackagePropertySetView = dataPackageView.properties;
Value
DataPackagePropertySetView DataPackagePropertySetView DataPackagePropertySetView DataPackagePropertySetView

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

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
var dataPackageOperation = dataPackageView.requestedOperation;
Value
DataPackageOperation DataPackageOperation DataPackageOperation DataPackageOperation

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

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
var bool = dataPackageView.contains(formatId);
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.

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<Uri>( Of Uri )
Windows.ApplicationModel.DataTransfer.DataPackageView.getApplicationLinkAsync().done( /* Your success and error handlers */ );
Returns
IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri>

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 )
Windows.ApplicationModel.DataTransfer.DataPackageView.getBitmapAsync().done( /* Your success and error handlers */ );
Returns

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 )
Windows.ApplicationModel.DataTransfer.DataPackageView.getDataAsync(formatId).done( /* Your success and error handlers */ );
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.

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 )
Windows.ApplicationModel.DataTransfer.DataPackageView.getHtmlFormatAsync().done( /* Your success and error handlers */ );
Returns

The HTML.

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<IReadOnlyDictionary<string, RandomAccessStreamReference>>( Of IMapView )
Windows.ApplicationModel.DataTransfer.DataPackageView.getResourceMapAsync().done( /* Your success and error handlers */ );
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.

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 )
Windows.ApplicationModel.DataTransfer.DataPackageView.getRtfAsync().done( /* Your success and error handlers */ );
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<IReadOnlyList<IStorageItem>> GetStorageItemsAsync()
Public Function GetStorageItemsAsync() As IAsyncOperation<IReadOnlyList<IStorageItem>>( Of IVectorView )
Windows.ApplicationModel.DataTransfer.DataPackageView.getStorageItemsAsync().done( /* Your success and error handlers */ );
Returns
IAsyncOperation<IVectorView<IStorageItem>> IAsyncOperation<IReadOnlyList<IStorageItem>> IAsyncOperation<IReadOnlyList<IStorageItem>> IAsyncOperation<IReadOnlyList<IStorageItem>>

An array of files and folders stored in a DataPackageView.

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 )
Windows.ApplicationModel.DataTransfer.DataPackageView.getTextAsync().done( /* Your success and error handlers */ );
Returns

The text.

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 )
Windows.ApplicationModel.DataTransfer.DataPackageView.getTextAsync(formatId).done( /* Your success and error handlers */ );
Parameters
formatId
Platform::String String String String

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

Returns

The text.

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<Uri>( Of Uri )
Windows.ApplicationModel.DataTransfer.DataPackageView.getUriAsync().done( /* Your success and error handlers */ );
Returns
IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri>

The Uri.

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<Uri>( Of Uri )
Windows.ApplicationModel.DataTransfer.DataPackageView.getWebLinkAsync().done( /* Your success and error handlers */ );
Returns
IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri> IAsyncOperation<Uri>

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 void
dataPackageView.reportOperationCompleted(value);
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.

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 )
Windows.ApplicationModel.DataTransfer.DataPackageView.requestAccessAsync().done( /* Your success and error handlers */ );
Returns

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

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 )
Windows.ApplicationModel.DataTransfer.DataPackageView.requestAccessAsync(enterpriseId).done( /* Your success and error handlers */ );
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.

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
dataPackageView.setAcceptedFormatId(formatId);
Parameters
formatId
Platform::String String String String

The format Id.

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
var protectionPolicyEvaluationResult = dataPackageView.unlockAndAssumeEnterpriseIdentity();
Returns

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

See Also