ShowOpen, ShowSave Methods, FileName, IniDir, FileTitle, DefExt, Filter, FilterIndex, Title Properties

Purpose

Display the CommDlg control's Open and Save As dialog box.

Syntax

CommDlg.ShowOpen
CommDlg.ShowSave

CommDlg.FileName [ = string ]
CommDlg.IniDir [ = string ]
CommDlg.FileTitle [ = string ]
CommDlg.DefExt [ = string ]
CommDlg.Filter [ = string ]
CommDlg.FilterIndex [ = integer ]
CommDlg.Title [ = string ]

Description

The FileName property returns or sets the path and filename of a selected file. In the CommDlg object, you can set the FileName property before opening a dialog box to set an initial filename.

The IniDir property is used to specify the initial directory for an Open or Save As dialog. If this property isn't specified, the current directory is used.

FileTitle returns or sets the name (without the path) of the file to open or save.

DefExt returns or sets the default filename extension for the dialog box, such as .txt or .doc. When a file with no extension is saved, the extension specified by this property is automatically appended to the filename.

Filter specifies the type of files that are displayed in the dialog box's file list box. For example, selecting the filter *.txt displays all text files. Use the pipe ( | ) symbol (ASCII 124) to separate the description and filter values. Don't include spaces before or after the pipe symbol, because these spaces will be displayed with the description and filter values. The following code shows an example of a filter that enables the user to select text files or graphic files that include bitmaps and icons:

Text (*.txt)|*.txt|Pictures (*.bmp;*.ico)|*.bmp;*.ico

When you specify more than one filter for an Open or Save As dialog box, use the FilterIndex property to determine which filter is displayed as the default. The index for the first defined filter is 1.

The Title property returns or sets the string displayed in the title bar of the dialog box. The default title for an Open dialog box is Open; the default title for a Save As dialog box is Save As.

The Flags property for ShowOpen and ShowSave can be:

cdoReadOnly $1 Causes the Read Only check box to be initially checked when the dialog box is created. This flag also indicates the state of the Read Only check box when the dialog box is closed.
cdoOverWritePrompt $2 Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file.
cdoHideReadOnly $4 Hides the Read Only check box.
cdoNoChangeDir $8 Forces the dialog box to set the current directory to what it was when the dialog box was opened.
cdoShowHelp $10 Displays the Help button.
cdoNoValidate $100 Allows invalid characters in the returned Filename.
cdoAllowMultiselect &H200 Allows multiple selections.
The user can select more than one file at run time by pressing the SHIFT key and using the UP ARROW and DOWN ARROW keys to select the desired files. When this is done, the FileName property returns a string containing the names of all selected files. The names in the string are delimited by spaces.
cdoExtensionDifferent $400 Indicates that the extension is different from DefExt property.
cdoPathMustExist $800 Only valid paths. If the user enters an invalid path, a warning message is displayed.
cdoFileMustExist $1000 Allows only names of existing files. If the user enters an invalid filename, a warning is displayed. This flag automatically sets the cdoPathMustExist flag.
cdoCreatePrompt $2000 Prompts the user to create a file that doesn't currently exist. This flag automatically sets the cdoPathMustExist and cdoFileMustExist flags.
cdoNoReadOnlyReturn $8000 The returned file won't have the Read Only attribute set and won't be in a write-protected directory.
cdoNoTestFileCreate $10000 Specifies that the file is not created before the dialog box is closed. This flag should be specified if the application saves the file on a create-non-modify network share. When an application specifies this flag, the library does not check for write protection, a full disk, an open drive door, or network protection. Applications using this flag must perform file operations carefully, because a file cannot be reopened once it is closed.
cdoNoNetworkButton $20000 Hides and disables the Network button.
cdoNoLongNames $40000 No long file names.
cdoExplorer $80000 Use the Explorer-like Open A File dialog box template. Works with Windows 95 and Windows NT 4.0.
cdoNorefLinks $100000 Do not dereference shell links (also known as shortcuts). By default, choosing a shell link causes it to be dereferenced by the shell.

Example

Ocx CommDlg cd

cd.FileName = "test.file"

cd.FileTitle = ""

cd.DefExt = "FILE"

cd.Filter = "Files (*.FILE)|*.FILE|All Files (*)|*"

cd.Title = "Select a File"

cd.Flags = cdoHideReadOnly + cdoFileMustExist

cd.ShowOpen

Message cd.FileName

See Also

CommDlg, Dlg Open, Dlg Save

{Created by Sjouke Hamstra; Last updated: 23/10/2014 by James Gaite}