TargetFileRequestedEventArgs Class

Definition

Provides information about a TargetFileRequested event.

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

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

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.

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

Properties

Request

Gets a TargetFileRequest object that is used to respond to a TargetFileRequested event.

Applies to

See also