导出 (0) 打印
全部展开
信息
您所需的主题如下所示。但此主题未包含在此库中。

FileSavePicker Class

表示允许用户为文件选择文件名、扩展名和存储位置的选择器。

语法


var fileSavePicker = new Windows.Storage.Pickers.FileSavePicker();

特性

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

成员

FileSavePicker类 具有这些类型的成员:

构造函数

FileSavePicker类 具有这些构造函数。

构造函数说明
FileSavePicker Creates a new instance of a FileSavePicker.

 

方法

The FileSavePicker 类 具有这些方法。 对于 C#、Visual Basic 和 C++,它还继承方法于Object 类.

方法说明
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.

 

属性

FileSavePicker类 具有这些属性。

属性访问类型说明

CommitButtonText

读/写Gets or sets the label text of the commit button in the file pickerUI.

DefaultFileExtension

读/写Gets or sets the default file name extension that the fileSavePicker gives to files to be saved.

FileTypeChoices

只读Gets the collection of valid file types that the user can choose to assign to a file.

SettingsIdentifier

读/写Gets or sets the settings identifier associated with the current FileSavePicker instance.

SuggestedFileName

读/写Gets or sets the file name that the file save picker suggests to the user.

SuggestedSaveFile

读/写Gets or sets the storageFile that the file picker suggests to the user for saving a file.

SuggestedStartLocation

读/写Gets or sets the location that the file save picker suggests to the user as the location to 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");
    }
});


对于 C#,文件选择器示例演示如何检查您的应用程序是否在 EnsureUnsnapped 方法对齐。


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


要求

最低支持客户端

Windows 8 [仅 Windows 应用商店应用程序]

最低支持服务器

Windows Server 2012 [仅 Windows 应用商店应用程序]

命名空间

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

元数据

Windows.winmd

另请参见

文件选择器示例
快速入门:通过文件选择器访问文件
如何通过文件选择器保存文件
Windows.Storage.StorageFile class

 

 

显示:
© 2014 Microsoft