Represents a file picker that lets the user choose the file name, extension, and storage location for a file.
Syntax
var fileSavePicker = new Windows.Storage.Pickers.FileSavePicker();
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- MuseAttribute()
- VersionAttribute(NTDDI_WIN8)
Members
The FileSavePicker class has these types of members:
Constructors
The FileSavePicker class has these constructors.
| Constructor | Description |
|---|---|
| FileSavePicker | Creates a new instance of a FileSavePicker. |
Methods
The FileSavePicker class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| PickSaveFileAsync | Shows the file picker so that the user can save a file and set the file name, extension, and location of the file to be saved. |
Properties
The FileSavePicker class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read/write | Gets or sets the label text of the commit button in the file pickerUI. | |
| Read/write | Gets or sets the default file name extension that the fileSavePicker gives to files to be saved. | |
| Read-only | Gets the collection of valid file types that the user can choose to assign to a file. | |
| Read/write | Gets or sets the settings identifier associated with the current FileSavePicker instance. | |
| Read/write | Gets or sets the file name that the file save picker suggests to the user. | |
| Read/write | Gets or sets the storageFile that the file picker suggests to the user for saving a file. | |
| Read/write | Gets or sets the location that the file save picker suggests to the user as the location to save a file. |
Remarks
To learn how to save files through the file picker, see How to save files through file pickers.
To get started accessing files and folders file pickers, see Quickstart: Accessing files with file pickers.
Warning If you try to show the file picker while your app is snapped the file picker will not be shown and an exception will be thrown. You can avoid this by making sure your app is not snapped or by unsnapping it before you call the file picker. The following code examples and the File picker sample show you how.
Examples
The File picker sample demonstrates how to check whether the app is snapped, how to set file picker properties, and how to show a file picker so that the user can save a file.
// Verify that we are currently not snapped, or that we can unsnap to open the picker var currentState = Windows.UI.ViewManagement.ApplicationView.value; if (currentState === Windows.UI.ViewManagement.ApplicationViewState.snapped && !Windows.UI.ViewManagement.ApplicationView.tryUnsnap()) { // Fail silently if we can't unsnap return; } // Create the picker object and set options var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary; // Dropdown of file types the user can save the file as savePicker.fileTypeChoices.insert("Plain Text", [".txt"]); // Default file name if the user does not type one in or select a file to replace savePicker.suggestedFileName = "New Document"; savePicker.pickSaveFileAsync().then(function (file) { if (file) { // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync. Windows.Storage.CachedFileManager.deferUpdates(file); // write to file Windows.Storage.FileIO.writeTextAsync(file, file.name).done(function () { // Let Windows know that we're finished changing the file so the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. Windows.Storage.CachedFileManager.completeUpdatesAsync(file).done(function (updateStatus) { if (updateStatus === Windows.Storage.Provider.FileUpdateStatus.complete) { WinJS.log && WinJS.log("File " + file.name + " was saved.", "sample", "status"); } else { WinJS.log && WinJS.log("File " + file.name + " couldn't be saved.", "sample", "status"); } }); }); } else { WinJS.log && WinJS.log("Operation cancelled.", "sample", "status"); } });
For C#, the File picker sample demonstrates how to check whether your app is snapped in the EnsureUnsnapped method.
internal bool EnsureUnsnapped() { // FilePicker APIs will not work if the application is in a snapped state. // If an app wants to show a FilePicker while snapped, it must attempt to unsnap first bool unsnapped = ((ApplicationView.Value != ApplicationViewState.Snapped) || ApplicationView.TryUnsnap()); if (!unsnapped) { NotifyUser("Cannot unsnap the sample.", NotifyType.StatusMessage); } return unsnapped; }
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
See also
- File picker sample
- Quickstart: Accessing files with file pickers
- How to save files through file pickers
- Windows.Storage.StorageFile class
Build date: 2/25/2013