Share via


TargetFileRequest 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 ref class TargetFileRequest sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class TargetFileRequest final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class TargetFileRequest
Public NotInheritable Class TargetFileRequest
Inheritance
Object Platform::Object IInspectable TargetFileRequest
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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);

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

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

Methods

GetDeferral()

Gets a TargetFileRequestDeferral that the app providing the save location can use to respond asynchronously to a TargetFileRequested event.

Applies to