Bewerken

Share via


SaveFileDialog Class

Definition

Represents a common dialog that allows the user to specify a filename to save a file as. SaveFileDialog 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
Inheritance
SaveFileDialog
Inheritance

Examples

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

Remarks

You cannot declare this managed class in XAML.

Constructors

SaveFileDialog()

Initializes a new instance of the SaveFileDialog class.

Properties

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.

(Inherited from FileDialog)
AddToRecent

Gets or sets a value indicating whether the dialog box will add the item being opened or saved to the recent documents list.

(Inherited from CommonItemDialog)
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.

(Inherited from FileDialog)
CheckPathExists

Gets or sets a value that specifies whether warnings are displayed if the user types invalid paths and file names.

(Inherited from FileDialog)
ClientGuid

Gets or sets a GUID to associate with the dialog's persisted state.

(Inherited from CommonItemDialog)
CreatePrompt

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.

CreateTestFile

Gets or sets a value indicating whether the dialog box will attempt to create a test file at the selected path.

CustomPlaces

Gets or sets the list of custom places for file dialog boxes.

(Inherited from FileDialog)
DefaultDirectory

Gets or sets the directory displayed by the file dialog box if no recently used directory value is available.

(Inherited from CommonItemDialog)
DefaultExt

Gets or sets a value that specifies the default extension string to use to filter the list of files that are displayed.

(Inherited from FileDialog)
DereferenceLinks

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

(Inherited from FileDialog)
FileName

Gets or sets a string containing the full path of the file selected in a file dialog.

(Inherited from FileDialog)
FileNames

Gets an array that contains one file name for each selected file.

(Inherited from FileDialog)
Filter

Gets or sets the filter string that determines what types of files are displayed from either the OpenFileDialog or SaveFileDialog.

(Inherited from FileDialog)
FilterIndex

Gets or sets the index of the filter currently selected in a file dialog.

(Inherited from FileDialog)
InitialDirectory

Gets or sets the initial directory that is displayed by a file dialog.

(Inherited from FileDialog)
Options

Gets the Win32 common file dialog flags that are used by file dialogs for initialization.

(Inherited from FileDialog)
OverwritePrompt

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.

(Inherited from FileDialog)
RootDirectory

Gets or sets the directory displayed as the navigation root for the dialog.

(Inherited from CommonItemDialog)
SafeFileName

Gets a string that only contains the file name for the selected file.

(Inherited from FileDialog)
SafeFileNames

Gets an array that contains one safe file name for each selected file.

(Inherited from FileDialog)
ShowHiddenItems

Gets or sets a value indicating whether the dialog box will show hidden and system items regardless of user preferences.

(Inherited from CommonItemDialog)
Tag

Gets or sets an object associated with the dialog. This provides the ability to attach an arbitrary object to the dialog.

(Inherited from CommonDialog)
Title

Gets or sets the text that appears in the title bar of a file dialog.

(Inherited from FileDialog)
ValidateNames

Gets or sets a value indicating whether the dialog accepts only valid Win32 file names.

(Inherited from FileDialog)

Methods

CheckPermissionsToShowDialog()

Determines whether sufficient permissions for displaying a dialog exist.

(Inherited from CommonDialog)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

Defines the common file dialog hook procedure that is overridden to add common functionality to a file dialog.

(Inherited from FileDialog)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnFileOk(CancelEventArgs)

Raises the FileOk event.

(Inherited from FileDialog)
OnItemOk(CancelEventArgs)

Raises the FileOk event.

(Inherited from FileDialog)
OpenFile()

Creates a read-write file stream for the filename selected by the user using SaveFileDialog.

Reset()

Resets all SaveFileDialog properties to their default values.

RunDialog(IntPtr)

RunDialog(IntPtr) is called to display a file dialog in a derived class, such as OpenFileDialog and SaveFileDialog.

(Inherited from FileDialog)
ShowDialog()

Displays a common dialog.

(Inherited from CommonDialog)
ShowDialog(Window)

Displays a common dialog.

(Inherited from CommonDialog)
ToString()

Returns a string that represents a file dialog.

(Inherited from FileDialog)

Events

FileOk

Occurs when the user selects a file name by either clicking the Open button of the OpenFileDialog or the Save button of the SaveFileDialog.

(Inherited from FileDialog)

Applies to

See also