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.

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

public : IAsyncOperation<Uri> GetApplicationLinkAsync()public IAsyncOperation<Uri> GetApplicationLinkAsync()Public Function GetApplicationLinkAsync() As IAsyncOperation( Of Uri )// You can use this method in JavaScript.

GetBitmapAsync()GetBitmapAsync()GetBitmapAsync()GetBitmapAsync()

public : IAsyncOperation<RandomAccessStreamReference> GetBitmapAsync()public IAsyncOperation<RandomAccessStreamReference> GetBitmapAsync()Public Function GetBitmapAsync() As IAsyncOperation( Of RandomAccessStreamReference )// You can use this method in JavaScript.

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

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

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

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.

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

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

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

GetTextAsync()GetTextAsync()GetTextAsync()GetTextAsync()

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

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.

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.

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.

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.

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.

public : ProtectionPolicyEvaluationResult UnlockAndAssumeEnterpriseIdentity()public ProtectionPolicyEvaluationResult UnlockAndAssumeEnterpriseIdentity()Public Function UnlockAndAssumeEnterpriseIdentity() As ProtectionPolicyEvaluationResult// You can use this method in JavaScript.