TargetFileRequestedEventArgs class

Applies to Windows and Windows Phone

Provides information about a targetfilerequested event.

Syntax


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

Attributes

[Version(0x06020000)]

Members

The TargetFileRequestedEventArgs class has these types of members:

Methods

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

Properties

The TargetFileRequestedEventArgs class has these properties.

PropertyAccess typeDescription

Request

Read-onlyGets a targetFileRequest object that is used to respond to a targetfilerequested event.

 

Remarks

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.

Examples

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;
        deferral.complete();
    }, function () {
        // Set the targetFile property to null and complete the deferral to indicate failure
        e.request.targetFile = null;
        deferral.complete();
    });
};

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

In the example, e contains a TargetFileRequestedEventArgs object.

Requirements

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]

Namespace

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

Metadata

Windows.winmd

See also

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

 

 

Show:
© 2014 Microsoft