SaveFileDialog 类

定义

表示一个通用对话框,用户可以使用此对话框来指定一个要将文件另存为的文件名。Represents a common dialog that allows the user to specify a filename to save a file as. 在部分信任情况下执行的应用程序不能使用 SaveFileDialogSaveFileDialog cannot be used by an application that is executing under partial trust.

public ref class SaveFileDialog sealed : Microsoft::Win32::FileDialog
public sealed class SaveFileDialog : Microsoft.Win32.FileDialog
type SaveFileDialog = class
    inherit FileDialog
Public NotInheritable Class SaveFileDialog
Inherits FileDialog
继承
SaveFileDialog

示例

下面的示例演示如何创建SaveFileDialog并处理结果。The following example demonstrates how to create a SaveFileDialog and process the result.

// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension

// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();

// Process save file dialog box results
if (result == true)
{
    // Save document
    string filename = dlg.FileName;
}
' Configure save file dialog box
Dim dlg As New Microsoft.Win32.SaveFileDialog()
dlg.FileName = "Document" ' Default file name
dlg.DefaultExt = ".txt" ' Default file extension
dlg.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension

' Show save file dialog box
Dim result? As Boolean = dlg.ShowDialog()

' Process save file dialog box results
If result = True Then
    ' Save document
    Dim filename As String = dlg.FileName
End If

注解

下图显示了SaveFileDialog的。 Windows VistaWindows VistaThe following figure shows a SaveFileDialog for Windows VistaWindows Vista.

"另存为" 对话框Save As dialog box

从开始, "打开和保存文件" 对话框的左侧有一个 "收藏夹链接" 面板, 使用户能够快速导航到不同的位置。 Windows VistaWindows VistaStarting in Windows VistaWindows Vista, open and save file dialog boxes have a Favorite Links panel on the left side of the dialog box that allows the user to quickly navigate to a different location. 这些链接称为自定义位置。These links are called custom places. CustomPlaces使用属性设置此链接列表。Use the CustomPlaces property to set this list of links.

XAML 文本用法XAML Text Usage

不能在中XAMLXAML声明此托管类。You cannot declare this managed class in XAMLXAML.

构造函数

SaveFileDialog()

初始化 SaveFileDialog 类的新实例。Initializes a new instance of the SaveFileDialog class.

属性

AddExtension

获取或设置一个值,该值指示如果用户省略扩展名,文件对话框是否自动在文件名中添加扩展名。Gets or sets a value indicating whether a file dialog automatically adds an extension to a file name if the user omits an extension.

(继承自 FileDialog)
CheckFileExists

获取或设置一个值,该值指示如果用户指定不存在的文件名,文件对话框是否显示警告。Gets or sets a value indicating whether a file dialog displays a warning if the user specifies a file name that does not exist.

(继承自 FileDialog)
CheckPathExists

获取或设置一个值,该值指定如果用户键入无效的路径和文件名,是否显示警告。Gets or sets a value that specifies whether warnings are displayed if the user types invalid paths and file names.

(继承自 FileDialog)
CreatePrompt

获取或设置一个值,该值指示如果用户指定一个不存在的文件,SaveFileDialog 是否提示用户以允许创建文件。Gets or sets a value indicating whether SaveFileDialog prompts the user for permission to create a file if the user specifies a file that does not exist.

CustomPlaces

获取或设置文件对话框的自定义空间的列表。Gets or sets the list of custom places for file dialog boxes.

(继承自 FileDialog)
DefaultExt

获取或设置一个值,该值指定用来筛选显示的文件列表的默认扩展名字符串。Gets or sets a value that specifies the default extension string to use to filter the list of files that are displayed.

(继承自 FileDialog)
DereferenceLinks

获取或设置一个值,该值指示文件对话框是返回快捷方式引用的文件的位置,还是返回快捷方式文件 (.lnk) 的位置。Gets or sets a value indicating whether a file dialog returns either the location of the file referenced by a shortcut or the location of the shortcut file (.lnk).

(继承自 FileDialog)
FileName

获取或设置一个字符串,其中包含在文件对话框中选定的文件的完整路径。Gets or sets a string containing the full path of the file selected in a file dialog.

(继承自 FileDialog)
FileNames

获取一个数组,其中包含与每个选定文件一一对应的文件名。Gets an array that contains one file name for each selected file.

(继承自 FileDialog)
Filter

获取或设置筛选器字符串,该字符串确定在 OpenFileDialogSaveFileDialog 中显示的文件类型。Gets or sets the filter string that determines what types of files are displayed from either the OpenFileDialog or SaveFileDialog.

(继承自 FileDialog)
FilterIndex

获取或设置文件对话框中当前选定的筛选器的索引。Gets or sets the index of the filter currently selected in a file dialog.

(继承自 FileDialog)
InitialDirectory

获取或设置文件对话框显示的初始目录。Gets or sets the initial directory that is displayed by a file dialog.

(继承自 FileDialog)
Options

获取 Win32Win32 通用文件对话框标志,文件对话框使用这些标志来进行初始化。Gets the Win32Win32 common file dialog flags that are used by file dialogs for initialization.

(继承自 FileDialog)
OverwritePrompt

获取或设置一个值,该值指示如果用户指定的文件名已存在,SaveFileDialog 是否显示警告。Gets or sets a value indicating whether SaveFileDialog displays a warning if the user specifies the name of a file that already exists.

RestoreDirectory

不实现此属性。This property is not implemented.

(继承自 FileDialog)
SafeFileName

获取一个字符串,其中仅包含选定文件的文件名。Gets a string that only contains the file name for the selected file.

(继承自 FileDialog)
SafeFileNames

获取一个数组,其中包含与每个选定文件一一对应的安全文件名。Gets an array that contains one safe file name for each selected file.

(继承自 FileDialog)
Tag

获取或设置与对话框关联的对象。Gets or sets an object associated with the dialog. 这将提供向对话框附加任意对象的能力。This provides the ability to attach an arbitrary object to the dialog.

(继承自 CommonDialog)
Title

获取或设置在文件对话框的标题栏中显示的文本。Gets or sets the text that appears in the title bar of a file dialog.

(继承自 FileDialog)
ValidateNames

获取或设置一个值,该值指示对话框是否只接受有效的 Win32Win32 文件名。Gets or sets a value indicating whether the dialog accepts only valid Win32Win32 file names.

(继承自 FileDialog)

方法

CheckPermissionsToShowDialog()

确定是否有足够的权限来显示对话框。Determines whether sufficient permissions for displaying a dialog exist.

(继承自 CommonDialog)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

定义要重写的通用文件对话框挂钩过程,以便向文件对话框添加通用功能。Defines the common file dialog hook procedure that is overridden to add common functionality to a file dialog.

(继承自 FileDialog)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnFileOk(CancelEventArgs)

引发 FileOk 事件。Raises the FileOk event.

(继承自 FileDialog)
OpenFile()

为用户使用 SaveFileDialog 选定的文件名创建读/写文件流。Creates a read-write file stream for the filename selected by the user using SaveFileDialog.

Reset()

将所有 SaveFileDialog 属性重置为其默认值。Resets all SaveFileDialog properties to their default values.

RunDialog(IntPtr)

调用 RunDialog(IntPtr) 以在派生类中显示文件对话框,如 OpenFileDialogSaveFileDialogRunDialog(IntPtr) is called to display a file dialog in a derived class, such as OpenFileDialog and SaveFileDialog.

(继承自 FileDialog)
ShowDialog()

显示通用对话框。Displays a common dialog.

(继承自 CommonDialog)
ShowDialog(Window)

显示通用对话框。Displays a common dialog.

(继承自 CommonDialog)
ToString()

返回表示文件对话框的字符串。Returns a string that represents a file dialog.

(继承自 FileDialog)

事件

FileOk

当用户通过单击 OpenFileDialog 的“打开”按钮或 SaveFileDialog 的“保存”按钮选择某个文件名时发生。Occurs when the user selects a file name by either clicking the Open button of the OpenFileDialog or the Save button of the SaveFileDialog.

(继承自 FileDialog)

适用于

另请参阅