FileSavePicker class

Applies to Windows and Windows Phone

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

[Muse()]
[Version(0x06020000)]

Members

The FileSavePicker class has these types of members:

Constructors

The FileSavePicker class has these constructors.

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

MethodDescription
PickSaveFileAndContinue Shows the file picker so that the user can save a file, deactivating and the app and reactivating it when the operation is complete. (Windows Phone Store app)
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. (Windows Store app)

 

Properties

The FileSavePicker class has these properties.

PropertyAccess typeDescription

CommitButtonText

Read/writeGets or sets the label text of the commit button in the file pickerUI.

ContinuationData

Read-onlyGets a set of values to be populated by the app before a PickSaveFileAndContinue operation that deactivates the app in order to provide context when the app is activated. (Windows Phone Store app)

DefaultFileExtension

Read/writeGets or sets the default file name extension that the fileSavePicker gives to files to be saved.

FileTypeChoices

Read-onlyGets the collection of valid file types that the user can choose to assign to a file.

SettingsIdentifier

Read/writeGets or sets the settings identifier associated with the current FileSavePicker instance.

SuggestedFileName

Read/writeGets or sets the file name that the file save picker suggests to the user.

SuggestedSaveFile

Read/writeGets or sets the storageFile that the file picker suggests to the user for saving a file.

SuggestedStartLocation

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

To learn about using file pickers in Windows Phone Store apps, see How to continue your Windows Phone app after calling a file picker.

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]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

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

Metadata

Windows.winmd

See also

File picker sample
Quickstart: Accessing files with file pickers
How to save files through file pickers
How to continue your Windows Phone app after calling a file picker
Windows.Storage.StorageFile class

 

 

Show:
© 2014 Microsoft