FileDialog Class

FileDialog Class

This Package | All Packages

CommonDialog
  |
  +--FileDialog
public abstract class FileDialog
extends CommonDialog

Represents the abstract base class for the OpenFileDialog and SaveFileDialog classes.

Fields
Name Description
ALLOWMULTISELECT Specifies that the File Name list box allows multiple selections.
CREATEPROMPT If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file.
EXTENSIONDIFFERENT Specifies that the user has typed a filename extension that differs from the extension specified by the DefaultExt property.
FILEMUSTEXIST Specifies that the user can type only names of existing files in the File Name entry field.
HIDEREADONLY Hides the Read Only check box.
NOCHANGEDIR Restores the current directory to its original value if the user changed the directory while searching for files.
NODEREFERENCELINKS Directs the dialog box to return the path and filename of the selected shortcut (.LNK) file.
NONETWORKBUTTON Hides and disables the Network button.
NOREADONLYRETURN Specifies that the returned file does not have the Read Only check box checked and is not in a write-protected directory.
NOTESTFILECREATE Specifies that the file is not created before the dialog box is closed.
NOVALIDATE Specifies that the common dialog boxes allow invalid characters in the returned filename.
OVERWRITEPROMPT Causes the Save As dialog box to generate a message box if the selected file already exists.
PATHMUSTEXIST Specifies that the user can type only valid paths and filenames.
READONLY Causes the Read Only check box to be checked initially when the dialog box is created.
SHAREAWARE Specifies that if opening the selected file fails because of a network sharing violation, the error is ignored and the dialog box returns the selected filename.
SHOWHELP Causes the dialog box to display the Help button.

Constructors
Name Description
FileDialog() Constructs a new FileDialog.

Methods
Name Description
getDefaultExt() Returns the default file extension.
getFilename() Returns the filename selected in the file dialog.
getFilenames() Returns the list of filenames selected in the file dialog.
getFilter() Returns the current filter string.
getFilterIndex() Returns the index of the filter currently selected in the file dialog.
getInitialDir() Returns the initial directory set for the file dialog.
getOptions() Returns the option flags currently set for the file dialog.
getTitle() Returns the title set for the file dialog.
hookProc(int hWnd, int msg, int wParam, int lParam) Common dialog hook procedure.
reset() Resets all properties to their default values.
runDialog(int hookProcPtr) Implements running of a file dialog.
setDefaultExt(String value) Sets the default extension.
setFilename(String value) Sets the filename used to initialize the File Name edit control.
setFilter(String value) Sets the filters for the file dialog.
setFilterIndex(int value) Sets the current filter index.
setInitialDir(String value) Sets the initial file dialog directory.
setOptions(int value) Sets the option flags for the file dialog.
setTitle(String value) Sets the file dialog title.

Fields

FileDialog.ALLOWMULTISELECT

Syntax
public static final int ALLOWMULTISELECT;
Description
Specifies that the File Name list box allows multiple selections. To access the full list of selected filenames, use the getFilenames method.

FileDialog.CREATEPROMPT

Syntax
public static final int CREATEPROMPT;
Description
If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file. If the user chooses to create the file, the dialog box closes and the function returns the specified name; otherwise, the dialog box remains open.

FileDialog.EXTENSIONDIFFERENT

Syntax
public static final int EXTENSIONDIFFERENT;
Description
Specifies that the user has typed a filename extension that differs from the extension specified by the DefaultExt property. The file dialog does not update this flag if DefaultExt is an empty string.

FileDialog.FILEMUSTEXIST

Syntax
public static final int FILEMUSTEXIST;
Description
Specifies that the user can type only names of existing files in the File Name entry field. If this flag is specified and the user enters an invalid name, the dialog box procedure displays a warning in a message box. If this flag is specified, the PATHMUSTEXIST flag is also used.

FileDialog.HIDEREADONLY

Syntax
public static final int HIDEREADONLY;
Description
Hides the Read Only check box.

FileDialog.NOCHANGEDIR

Syntax
public static final int NOCHANGEDIR;
Description
Restores the current directory to its original value if the user changed the directory while searching for files.

FileDialog.NODEREFERENCELINKS

Syntax
public static final int NODEREFERENCELINKS;
Description
Directs the dialog box to return the path and filename of the selected shortcut (.LNK) file. If this value is not given, the dialog box returns the path and filename of the file referenced by the shortcut

FileDialog.NONETWORKBUTTON

Syntax
public static final int NONETWORKBUTTON;
Description
Hides and disables the Network button.

FileDialog.NOREADONLYRETURN

Syntax
public static final int NOREADONLYRETURN;
Description
Specifies that the returned file does not have the Read Only check box checked and is not in a write-protected directory.

FileDialog.NOTESTFILECREATE

Syntax
public static final int NOTESTFILECREATE;
Description
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-nonmodify network sharepoint. 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.

FileDialog.NOVALIDATE

Syntax
public static final int NOVALIDATE;
Description
Specifies that the common dialog boxes allow invalid characters in the returned filename. If the edit control contains anything but spaces when the user clicks OK, the dialog returns the filename, whether it is valid or not. No default extension is added to the text.

FileDialog.OVERWRITEPROMPT

Syntax
public static final int OVERWRITEPROMPT;
Description
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.

FileDialog.PATHMUSTEXIST

Syntax
public static final int PATHMUSTEXIST;
Description
Specifies that the user can type only valid paths and filenames. If this flag is used and the user types an invalid path and filename in the File Name entry field, the dialog box function displays a warning in a message box.

FileDialog.READONLY

Syntax
public static final int READONLY;
Description
Causes the Read Only check box to be checked initially when the dialog box is created. This flag indicates the state of the Read Only check box when the dialog box is closed.

FileDialog.SHAREAWARE

Syntax
public static final int SHAREAWARE;
Description
Specifies that if opening the selected file fails because of a network sharing violation, the error is ignored and the dialog box returns the selected filename.

FileDialog.SHOWHELP

Syntax
public static final int SHOWHELP;
Description
Causes the dialog box to display the Help button.

Constructors

FileDialog.FileDialog

Syntax
protected FileDialog();
Description

Constructs a new FileDialog.

Methods

FileDialog.getDefaultExt

Syntax
public final String getDefaultExt();
Description

Returns the default file extension.

See Also
setDefaultExt

FileDialog.getFilename

Syntax
public final String getFilename();
Description

Returns the filename selected in the file dialog. If multiple files are selected, the return value is the first filename in the list. If no file is selected, the return value is an empty string.

See Also
getFilenames, setFilename

FileDialog.getFilenames

Syntax
public final String[] getFilenames();
Description

Returns the list of filenames selected in the file dialog. If no files are selected, the return value is an empty array.

See Also
getFilename, setFilenames

FileDialog.getFilter

Syntax
public final String getFilter();
Description

Returns the current filter string.

See Also
setFilter

FileDialog.getFilterIndex

Syntax
public final int getFilterIndex();
Description

Returns the index of the filter currently selected in the file dialog.

See Also
setFilterIndex

FileDialog.getInitialDir

Syntax
public final String getInitialDir();
Description

Returns the initial directory set for the file dialog.

See Also
setInitialDir

FileDialog.getOptions

Syntax
public final int getOptions();
Description

Returns the option flags currently set for the file dialog. The READONLY and EXTENSIONDIFFERENT flags are updated by the file dialog when the user clicks OK.

See Also
setOptions

FileDialog.getTitle

Syntax
public final String getTitle();
Description

Returns the title set for the file dialog.

See Also
setTitle

FileDialog.hookProc

Syntax
protected int hookProc( int hWnd, int msg, int wParam, int lParam );
Description

Common dialog hook procedure. Centers the dialog on the screen in response to a CDN_INITDONE notification.

FileDialog.reset

Syntax
public void reset();
Description

Resets all properties to their default values.

FileDialog.runDialog

Syntax
protected boolean runDialog( int hookProcPtr );
Description

Implements running of a file dialog.

FileDialog.setDefaultExt

Syntax
public final void setDefaultExt( String value );
Description

Sets the default extension. The file dialog append this extension to the filename if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period. The default value for the default extension is an empty string, which causes no extension to be appended.

See Also
getDefaultExt

FileDialog.setFilename

Syntax
public final void setFilename( String value );
Description

Sets the filename used to initialize the File Name edit control.

See Also
getFilename

FileDialog.setFilter

Syntax
public final void setFilter( String value );
Description

Sets the filters for the file dialog. The filter string must consist of a number of filter pairs, separated by "|" characters. The first string in each pair is a display string that describes the filter (for example, "Text files"), and the second string specifies the filter pattern (for example, "*.txt"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.txt;*.doc;*.bak"). A pattern string can be a combination of valid filename characters and the asterisk (*) wildcard character. Do not include spaces in the pattern string. The following is an example of a filter string:


  "Java files (*.java)|*.java|All files (*.*)|*.*"

The file dialog does not change the order of the filters. It displays them in the File Types combo box in the order specified by setFilter().

See Also
getFilter, setFilterIndex

FileDialog.setFilterIndex

Syntax
public final void setFilterIndex( int value );
Description

Sets the current filter index. The first pair of filter strings has an index value of 1, the second pair 2, and so on. You can specify an index on input to indicate the initial filter description and filter pattern for the dialog box. When the file dialog returns, getFilterIndex() returns the index of the currently displayed filter.

See Also
getFilterIndex, setFilter

FileDialog.setInitialDir

Syntax
public final void setInitialDir( String value );
Description

Sets the initial file dialog directory. If the specified directory is an empty string, the system uses the current directory as the initial directory.

See Also
getInitialDir

FileDialog.setOptions

Syntax
public final void setOptions( int value );
Description

Sets the option flags for the file dialog. The default value for the option flags is 0.

See Also
getOptions

FileDialog.setTitle

Syntax
public final void setTitle( String value );
Description

Sets the file dialog title. The given string is placed in the title bar of the dialog box. If specified title is an empty string, the system uses the default title (that is, "Save As" or "Open").

See Also
getTitle