Target​File​Request Target​File​Request Target​File​Request Class

Definition

Lets an app that provides a save location specify the storageFile that represents the file to save and get a deferral so the app can respond asynchronously to a targetFileRequested event.

public : sealed class TargetFileRequest : ITargetFileRequestpublic sealed class TargetFileRequest : ITargetFileRequestPublic NotInheritable Class TargetFileRequest Implements ITargetFileRequest
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The File picker sample demonstrates how to respond to a targetfilerequested event handler, including how to use the Request property to get the TargetFileRequest.


// Event handler
private async void OnTargetFileRequested(FileSavePickerUI sender, TargetFileRequestedEventArgs e)
{
    // Respond to TargetFileRequested event on the background thread on which it was raised

    // Requesting a deferral allows the app to call another asynchronous method and complete the request at a later time
    var deferral = e.Request.GetDeferral();

    // Create file and assign to TargetFile property
    e.Request.TargetFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(sender.FileName, CreationCollisionOption.GenerateUniqueName);

    // Complete the deferral to let the Picker know the request is finished
    deferral.Complete();
}

// Register for the event
fileSavePickerUI.TargetFileRequested += new TypedEventHandler<FileSavePickerUI, TargetFileRequestedEventArgs>(OnTargetFileRequested);

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

Remarks

If your app participates in the File Save Picker contract and a targetfilerequested event fires, your app should create a new storageFile that represents the file the user wants to save. The name of the storageFile you create must match the name of the file specified by the fileName property. The storageFile you create is returned to the app that called the file picker (the calling app) so that the calling app can write content to the file. Learn more about responding to this event in targetFileRequestedEventArgs.

Properties

TargetFile TargetFile TargetFile

Gets or sets the IStorageFile object that is provided to represent the file to save by the app that is providing the save location.

public : IStorageFile TargetFile { get; set; }public IStorageFile TargetFile { get; set; }Public ReadWrite Property TargetFile As IStorageFile
Value
IStorageFile IStorageFile IStorageFile

The object that represents the file to save. The app that called the file picker in order to save will write content to this file.

Attributes

Remarks

If your app (as the provider of the save location) can't provide an object for the file to save, set this property to null. Unless the user selects an existing file to save, your app should create a storageFile object to represent the file sets this property to that object.

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

See Also

Methods

GetDeferral() GetDeferral() GetDeferral()

Gets a targetFileRequestDeferral that the app providing the save location can use to respond asynchronously to a targetfilerequested event.

public : TargetFileRequestDeferral GetDeferral()public TargetFileRequestDeferral GetDeferral()Public Function GetDeferral() As TargetFileRequestDeferral
Returns

The targetFileRequestDeferral that the providing app can use asynchronously to indicate that it is finished responding to a targetfilerequested event.

Attributes

Remarks

Use this method to finish responding to a targetFileRequest event asynchronously. If this method is not called, the request is considered complete after the targetfilerequested event handler returns— regardless of outstanding asynchronous operations.

To signal that your app has finished its asynchronous response to the targetfilerequested event, call the targetFileRequestDeferral.complete method.

Learn more about responding asynchronously to a targetfilerequested event in targetFileRequestedEventArgs.

See Also

See Also