Prompts the user to open a file from the server.

This class allows you to check whether a file exists and to open it. The ShowReadOnly property determines whether a read-only check box appears in the dialog box. The ReadOnlyChecked property indicates whether the read-only check box is checked.

Most of the core functionality for this class is found in the FileDialog class.

If you want to give the user the ability to select a folder instead of a file, use FolderBrowserDialog instead.

For a full list of properties, methods and events see the API documentation.



The OpenFileDialog is able to filter the types of files shown to the user based on a given pattern. For example, the filter C# files|.cs|All files|.* will by default show users files in the given directory ending with .cs. The filter can be modified by changing the selection in the dropdown on the bottom right.

The FileDialog.FileName property returns the path selected by the user, which is the virtual path relative to the root. To retrieve the physical path on the server use FileDialog.MapPath().


The OpenFileDialog component has an optional "?" (Help) tool that allows you to process and display information to help users navigate the control.

How To

Connect to the File System

In order to view files, you must add at least one IFileSystemProvider to the Roots collection before showing the dialog.

//Using an absolute file path
OpenFileDialog filedialog = new OpenFileDialog(); 
filedialog.Roots.Add(new FileSystemProvider("C:\\", "Main_Directory"));
//Using a relative file path
OpenFileDialog filedialog = new OpenFileDialog(); 
filedialog.Roots.Add(new FileSystemProvider("./", "Main_Directory"));

Customize the Appearance

The OpenFileDialog component can be customized by applying appearances to each individual control within the dialog. This includes the textboxes, picker, and more.

To customize these controls, create a new class that inherits from FileDialogUI, add the custom OpenFileDialog constructor, and modify the controls within it:

public class CustomOpenFileDialogUI : FileDialogUI
		public CustomOpenFileDialogUI(OpenFileDialog openFileDialog) : base(openFileDialog)
			this.HeaderBackColor = Color.DarkOrange;
			foreach (ColumnHeader col in this.listView.Columns)
				col.BackColor = Color.DarkOrange;

After applying the OpenFileDialog's DialogTemplate property to the new class, the resulting popup will look like this:

For instructions on how to use a custom template to offer advanced customization of the OpenFileDialog, see below.

Last updated