SaveFileDialog Class


SaveFileDialog Class

Namespace

Windows.Forms

Creatable

Yes

Description

The SaveFileDialog class represents a common dialog box for selecting or saving a file. The SaveFileDialog class has properties that let you configure, display, and retrieve the results from this dialog box, from which the user selects a single file. The dialog does not create or update the file; it only indicates the file to be modified.

The following list discusses the more interesting members of the SaveFileDialog class.


AddExtension Property

Indicates whether the dialog box should automatically add the default file extension to the user-supplied file name. The default value is true.


DefaultExt Property

Defines the default file extension. The string should consist of the file extension only, without a leading period.


FileName Property

Returns the fully qualified file namethe file name with its complete path and extension. If no file is selected, the property returns an empty string.


Filter Property

Used to configure a filter string that indicates the types of files (by extension) to display in the dialog box. These types appear in the "Save as type" drop-down control on the dialog box. A single item consists of a file description, a vertical bar, and the file extension (usually "*." plus the file extension). If there are multiple extensions in a single item, they are separated by semicolons. If there are multiple items, they are separated by vertical bars. For example, the following code fragment assigns a filter string for text files and VB source code files:

     Dim savePrompt As New SaveFileDialog     savePrompt.Filter = _        "Text files (*.txt; *.vb)|*.txt;*.vb|" & _        "Visual Basic files (*.vb)|*.vb|" & _        "All files (*.*)|*.*" 


FilterIndex Property

Indicates the selected 1-based position in the Filter property's item list. The default is 1. If the user selects a different filter, this property is updated to reflect that change.


InitialDirectory Property

Indicates the initial directory to use when first displaying the dialog.


OverwritePrompt Property

Indicates whether a confirmation dialog box should appear automatically when the user selects an existing file. The default value is true.


RestoreDirectory Property

Indicates whether the current working (default) directory is restored before the dialog box closes. The default value is False.


ShowDialog Method

Displays the dialog box to the user. Once the user has dismissed the dialog box, the FileName property can be used to get the user's selection.


Title Property

Sets the title of the dialog box.

Example

The following code prompts the user for a filename to save.

     Dim selectFile As New SaveFileDialog     selectFile.OverwritePrompt = True     If (selectFile.ShowDialog(  ) = DialogResult.OK) Then        Console.WriteLine(selectFile.FileName)     End If 

Version Differences

The public interfaces used for this SaveFileDialog class and the related VB 6 CommonDialog control are quite different.

See Also

OpenFileDialog Class




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net