Skip to main content
DataPackage.SetDataProvider | setDataProvider method

Sets a delegate to handle requests from the target app.


dataPackage.setDataProvider(formatId, delayRenderer);

public void SetDataProvider(
  string formatId, 
  DataProviderHandler delayRenderer

Public Sub SetDataProvider(
  formatId As String,  
  delayRenderer As DataProviderHandler 

void SetDataProvider(
  String^ formatId, 
  DataProviderHandler^ delayRenderer



Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

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


Type: DataProviderHandler

A delegate that is responsible for processing requests from a target app.


Use the SetDataProvider method when your app supports a specific format, but does not want to supply the data until the target app requests it. We encourage you to use this method if your app shares content that can require significant processing time; for example, sharing a selection of photos, videos, or files.

When you use this method, you need to specify a format and a function. You can specify the format by using the StandardDataFormats class, or you can use a string value for a custom format. The function must put data in the DataPackage by using a method like SetData.

You must specify the extension of the StorageItems being passed to the Share Target.

The SetDataProvider method is different from the GetDeferral method of the DataRequest class. With GetDeferral, a source app can call a function that immediately puts the data in the DataPackage object. The SetDataProvider method is for more complex share operations where packaging the data to be shared is more time-intensive or resource-intensive.


var imageFile;
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.fileTypeFilter.replaceAll([".jpg", ".bmp", ".gif", ".png", ".wmv"]);
picker.pickSingleFileAsync().then(function (file) {
    logText("PickImage: Picker returned a file");
    imageFile = file;

function onDeferredImageRequested(request) {
    try {
        if (imageFile) {
            // This is to make sure deferral works even in synchronous case
            var deferral = request.getDeferral();
            var imageStreamRef = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
    } catch (exc) {
        // Error handling goes here.

function shareFiles() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", function (e) {
        var request = e.request; = "Share Files Example"; = "A demonstration that shows how to share files.";[".jpg", ".bmp", ".gif", ".png", ".wmv"]);, onDeferredImageRequested);

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::ApplicationModel::DataTransfer [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]


Windows::ApplicationModel::DataTransfer [C++]



See also