Edit this page

RadOpenFileDialog

RadOpenFileDialog is a modal dialog box that allows you to specify one or multiple filenames to open.

Figure 1: RadOpenFileDialog in single selection mode

Showing the dialog

To show the dialog call its ShowDialog method. If a valid file is opened when you press OK, the DialogResult property will return True and the FileName, and FileNames properties will be set. You can use FileName and FileNames to get the names of the selected items.

Note that when the ShowDialog method is called the UI of the host application will freeze until the dialog closes.

Example 1: Show a open file dialog

RadOpenFileDialog openFileDialog = new RadOpenFileDialog();
openFileDialog.Owner = theHostWindowInstance;
openFileDialog.ShowDialog();
if (openFileDialog.DialogResult == true)
{
    string fileName = openFileDialog.FileName;
}

Opening the selected file

You can open a read-only file stream for the selected file using the OpenFile method. Or alternatively you can use the FileName and FileNames properties and open the file manually.

Example 2: Open a file stream

RadOpenFileDialog openFileDialog = new RadOpenFileDialog();
openFileDialog.Owner = theHostWindowInstance;
openFileDialog.ShowDialog();
if (openFileDialog.DialogResult == true)
{
    Stream fileStream = openFileDialog.OpenFile();
}

Enabling multiple selection

The dialog supports single and multiple selection modes. By default you can select only one file at a time. To alter this you can set the Multiselect property of RadOpenFileDialog.

Example 3: Enable multiple selection

RadOpenFileDialog openFileDialog = new RadOpenFileDialog();
openFileDialog.Owner = theHostWindowInstance;
openFileDialog.Multiselect = true;

Figure 2: Multiple selection

Working with the selected files

You can get the paths of the selected files via the FileName and FileNames properties. Note that the properties are empty until the DialogResult is valid. When you open file(s) the properties will return the corresponding paths.

You can get only the name of the selected files, without the full path, via the SafeFileNames collection property.

Example 3: Get the selected file names

RadOpenFileDialog openFileDialog = new RadOpenFileDialog();
openFileDialog.Owner = theHostWindowInstance;
openFileDialog.Multiselect = true;
openFileDialog.ShowDialog();
if (openFileDialog.DialogResult == true)
{
    string filePath = openFileDialog.FileName;
    IEnumerable<string> filePaths = openFileDialog.FileNames;
    IEnumerable<string> fileNames = openFileDialog.SafeFileNames;
}

The FileName property can be set manually. This will change the value displayed in the selected file autocomplete box area. Note that setting this won't change the selected item in the list with the files.

See Also