Export (0) Print
Expand All
4 out of 5 rated this helpful - Rate this topic

SaveFileDialog Class

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.

Namespace:  Microsoft.Win32
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: Not mapped to an xmlns.
public sealed class SaveFileDialog : FileDialog
You cannot declare this managed class in XAML.

The SaveFileDialog type exposes the following members.

  NameDescription
Public methodSaveFileDialogInitializes a new instance of the SaveFileDialog class.
Top
  NameDescription
Public propertyAddExtensionGets 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.)
Public propertyCheckFileExistsGets 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.)
Public propertyCheckPathExistsGets or sets a value that specifies whether warnings are displayed if the user types invalid paths and file names. (Inherited from FileDialog.)
Public propertyCreatePromptGets 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.
Public propertyCustomPlacesGets or sets the list of custom places for file dialog boxes. (Inherited from FileDialog.)
Public propertyDefaultExtGets or sets a value that specifies the default extension string to use to filter the list of files that are displayed. (Inherited from FileDialog.)
Public propertyDereferenceLinksGets 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.)
Public propertyFileNameGets or sets a string containing the full path of the file selected in a file dialog. (Inherited from FileDialog.)
Public propertyFileNamesGets an array that contains one file name for each selected file. (Inherited from FileDialog.)
Public propertyFilterGets or sets the filter string that determines what types of files are displayed from either the OpenFileDialog or SaveFileDialog. (Inherited from FileDialog.)
Public propertyFilterIndexGets or sets the index of the filter currently selected in a file dialog. (Inherited from FileDialog.)
Public propertyInitialDirectoryGets or sets the initial directory that is displayed by a file dialog. (Inherited from FileDialog.)
Public propertyOverwritePromptGets or sets a value indicating whether SaveFileDialog displays a warning if the user specifies the name of a file that already exists.
Public propertyRestoreDirectoryThis property is not implemented. (Inherited from FileDialog.)
Public propertySafeFileNameGets a string that only contains the file name for the selected file. (Inherited from FileDialog.)
Public propertySafeFileNamesGets an array that contains one safe file name for each selected file. (Inherited from FileDialog.)
Public propertyTagGets or sets an object associated with the dialog. This provides the ability to attach an arbitrary object to the dialog. (Inherited from CommonDialog.)
Public propertyTitleGets or sets the text that appears in the title bar of a file dialog. (Inherited from FileDialog.)
Public propertyValidateNamesGets or sets a value indicating whether the dialog accepts only valid Win32 file names. (Inherited from FileDialog.)
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodOpenFileCreates a read-write file stream for the filename selected by the user using SaveFileDialog.
Public methodResetResets all SaveFileDialog properties to their default values. (Overrides FileDialog.Reset().)
Public methodShowDialog()Displays a common dialog. (Inherited from CommonDialog.)
Public methodShowDialog(Window)Displays a common dialog. (Inherited from CommonDialog.)
Public methodToStringReturns a string that represents a file dialog. (Inherited from FileDialog.)
Top
  NameDescription
Public eventFileOkOccurs 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.)
Top

The following figure shows a SaveFileDialog for Windows Vista.

Save As dialog box

Starting in Windows 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. Use the CustomPlaces property to set this list of links.

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 = ".text"; // 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;
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.