FileDialog
Namespace: Wisej.Web
Assembly: Wisej.Framework (4.1.0.0)
Displays a dialog box from which the user can select a file.
- C#
- VB.NET
public abstract class FileDialog : CommonDialog
Public MustInherit Class FileDialog
Inherits CommonDialog
This class is abstract. The current implementations in Wisej are OpenFileDialog and SaveFileDialog.
You can override this class or OpenFileDialog and SaveFileDialog to add your own custom behavior and localization.
You can:
- Override PromptFileNotFound. It's called when the specified file doesn't exist and the property CheckFileExists is true.
- Override CreateUI to create your custom Form when the method ShowDialog is called.
- Set the DialogTemplate to a Form class that has a constructor that accepts FileDialog as the single argument to change the User Interface (UI) of the file dialog.
- Override OnFileOk to provide your custom implementation of the actions to execute when the user presses the OK button.
You must add at least one FileSystemProvider to the Roots collection before showing the dialog.
Constructors
FileDialog()
Initializes a new instance of FileDialog.
FileDialog(roots)
Initializes a new instance of FileDialog using the initial roots .
| Name | Type | Description |
|---|---|---|
| roots | IFileSystemProvider[] | Initial file systems to load in the FolderBrowserDialog. |
FileDialog(container)
Initializes a new instance of the FileDialog extender with a specified container.
| Name | Type | Description |
|---|---|---|
| container | IContainer | An IContainer that represents the container of the FileDialog component. |
Properties
AddExtension
Boolean: Returns or sets whether the dialog box automatically adds an extension to a file name if the user omits the extension. (Default: True)
Value: true if the dialog box adds an extension to a file name if the user omits the extension; otherwise, false. The default value is true.
CheckFileExists
Boolean: Returns or sets whether the dialog box displays a warning if the user specifies a file name that does not exist. (Default: False)
Value: true if the dialog box displays a warning if the user specifies a file name that does not exist; otherwise, false. The default value is false.
DefaultExtension
String: Returns or sets the default file name extension. (Default: "")
Value: The default file name extension. The returned string does not include the period. The default value is an empty string ("").
FileName
String: Returns or sets a string containing the file name selected in the file dialog box. (Default: "")
Value: The file name selected in the file dialog box. The default value is an empty string ("").
FileNames
String[]: Returns the file names of all selected files in the dialog box.
Value: An array of type String, containing the file names of all selected files in the dialog box.
FileSystem
IFileSystemProvider: Returns the IFileSystemProvider that contains the selected FileName.
Filter
String: Returns or sets the current file name filter string, which determines the choices that appear in the "Save as file type" or "Files of type" box in the dialog box. (Default: "")
Value: The file filtering options available in the dialog box.
FilterIndex
Int32: Returns or sets the index of the filter currently selected in the file dialog box. (Default: 1)
Value: A value containing the index of the filter currently selected in the file dialog box. The default value is 1.
InitialDirectory
String: Returns or sets the initial directory displayed by the file dialog box. (Default: "")
Value: The initial directory displayed by the file dialog box. The default is an empty string ("").
Roots
FileDialogRootCollection: List of root IFileSystemProvider file systems displayed by the FileDialog.
The Roots collection and the IFileSystemProvider implementations allow the application to use arbitrary names mapped to a specific path.
For example, the app may add a root object named "Documents" to "c:\users[logged-user-id]\files\documents". Each user will see "Documents" as the root, but will also see only the files in the [logged-user-id] directory.
Example:
using (var dialog = new OpenFileDialog())
{
dialog.Roots.Add(new FileSystemProvider("C:\\Users\\Files\\Billy", "My Files"));
if (dialog.ShowDialog() == DialogResult.OK)
{
var stream = dialog.FileSystem.OpenFileStream(dialog.FileName, FileMode.Open, FileAccess.Read);
...
}
}
ShowHelp
Boolean: Returns or sets whether the Help button is displayed in the file dialog box. (Default: False)
Value: true if the dialog box includes a help button; otherwise, false. The default value is false.
Title
String: Returns or sets the file dialog box title. (Default: "")
Value: The file dialog box title. The default value is an empty string ("").
Methods
CreateUI()
Creates the UI for the CommonDialog.
Returns: Form. An instance of Form.
GetRoot(path)
Returns the IFileSystemProvider that contains the specified path .
Returns: IFileSystemProvider. The IFileSystemProvider that contains the specified path or null if not found.
MapPath(filePath)
Maps the virtual path to the corresponding physical path on the specific IFileSystemProvider implementation.
| Parameter | Type | Description |
|---|---|---|
| filePath | String | Virtual path to map to the corresponding physical path. |
Returns: String. The physical path for the IFileSystemProvider implementation.
OnFileOk(e)
Fires the FileOk event.
| Parameter | Type | Description |
|---|---|---|
| e | CancelEventArgs | A CancelEventArgs that contains the event data. |
OnLoadPath(e)
Fires the LoadPath event.
| Parameter | Type | Description |
|---|---|---|
| e | FileDialogLoadPathEventArgs | A FileDialogLoadPathEventArgs object that provides the event data. |
ProcessFileNames(fileNames)
Receives the file names selected by the user and validates them according to the properties set in the FileDialog instance.
| Parameter | Type | Description |
|---|---|---|
| fileNames | String[] | Array containing the selected file paths. |
Returns: Boolean. True if the files have been validated and the dialog can close; otherwise false to keep the dialog open.
PromptFileNotFound(fileName)
Informs the user that the file specified in fileName doesn't exist. You can override this method to provide your text and localization.
| Parameter | Type | Description |
|---|---|---|
| fileName | String | Name of the file that doesn't exist. |
Reset()
Resets all properties to their default values.
Events
FileOk
CancelEventHandler Fired when the user clicks on the Open or Save button on a file dialog box.
LoadPath
FileDialogLoadPathEventHandler Fired when the file dialog is loading a file or folder.
Inherited By
| Name | Description |
|---|---|
| OpenFileDialog | Prompts the user to open a file from the server. |
| SaveFileDialog | Prompts the user to select a location for saving a file on the server. |