CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.InitialDirectory = "C:\\Users\\Public\\Pictures"; dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { string selectedFolder = dialog.FileName; // use the selected folder }
CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.InitialDirectory = "C:\\Users\\Public\\Pictures"; dialog.Filters.Add(new CommonFileDialogFilter("Image Files", "*.png;*.jpg;*.gif")); dialog.Multiselect = true; CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { foreach (string fileName in dialog.FileNames) { // use the selected file } }This example shows how to use the CommonOpenFileDialog to select multiple files with a specific file extension filter. The InitialDirectory property is set to a default directory, a filter is added to limit the selection to image files with the extensions *.png, *.jpg, or *.gif. The Multiselect property is set to true to allow multiple file selection. The ShowDialog method is called to display the dialog box and the result is checked to see if the user clicked the Ok button. If so, the selected file names are obtained from the FileNames property and can be used in a loop.