TargetFileRequestedEventArgs class

TargetFileRequestedEventArgs class

Provides information about a targetfilerequested event.


/* For information about creating or accessing this object, see Remarks. */


The TargetFileRequestedEventArgs class has these types of members:


The TargetFileRequestedEventArgs class inherits methods from the Object class (C#/VB/C++).


The TargetFileRequestedEventArgs class has these properties.

PropertyAccess typeDescription



Gets a targetFileRequest object that is used to respond to a targetfilerequested event.



This object is passed to the event handler for targetfilerequested events.

Responding to a targetfilerequested event

If your app participates in the File Save Picker contract and a targetfilerequested event fires, your app should respond by following these steps:

  1. Get a targetFileRequest using the targetFileRequestedEventArgs.request property.
  2. Create (or retrieve) a storageFile to represent the file to save; this storageFile is returned to the app that called the file picker to save and used by the calling app to write content to the file.

    The file name and extension of the object that represents the file must match the file name and extension specified by the user (and accessible through FileName) or the attempt to save the file will fail. If the attempt fails, the user can try to save the file again.

    If your app (as the provider of the save location) can't provide an object for the file to save, set targetFileRequest.targetFile to null.

  3. Set targetFileRequest.targetFile to the storageFile object.

Responding asynchronously

If your app, which is providing the save location, can't finish responding to the targetfilerequested event before it returns from its event handler (for example, if your app calls an asynchronous method), you can complete your response asynchronously by deferring.

Your app, as the provider of the save location, can defer in order to respond to the event asynchronously by following these steps:

  1. Get a targetFileRequest using the targetFileRequestedEventArgs.request property.
  2. Call targetFileRequest.getDeferral to get a targetFileRequestDeferral object.
  3. Perform the steps needed to respond to the targetfilerequested event (described in the preceding section).

  4. Call targetFileRequestDeferral.complete to signal that your app has finished responding to the targetfilerequested event.


The File picker sample demonstrates how to respond to a targetfilerequested event.

// Event handler
function onTargetFileRequested(e) {
    var deferral;
    deferral = e.request.getDeferral();

    // Create a file to pass to the file picker which then gives it to the calling app
    Windows.Storage.ApplicationData.current.localFolder.createFileAsync(fileSavePickerUI.fileName).done(function (file) {
            // Assign the resulting file to the targetFile property and complete the deferral to indicate success
        e.request.targetFile = file;
    }, function () {
        // Set the targetFile property to null and complete the deferral to indicate failure
        e.request.targetFile = null;

// Register for the event
fileSavePickerUI.addEventListener("targetfilerequested", onTargetFileRequested, false);

In the example, e contains a TargetFileRequestedEventArgs object.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0 [for Xbox, see UWP features that aren't yet supported on Xbox]

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::Storage::Pickers::Provider [C++]



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

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

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


Windows::Storage::Pickers::Provider [C++]





See also

FileSavePickerUI.TargetFileRequested event
TargetFileRequest class
TargetFileRequest.TargetFile property
TargetFileRequest.GetDeferral method
TargetFileRequestDeferral class
TargetFileRequestDeferral.Complete method
Windows.Storage.StorageFile class



© 2016 Microsoft