C# – How to customize OpenFileDialog to select multiple folders and files?

If you use the FileNames property instead of the FileName property, you get a string array of each file selected, you select multiple files using the shift key. Like so:

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog x = new OpenFileDialog();
    x.Multiselect = true;
    x.ShowDialog();
    string[] result = x.FileNames;

    foreach (string y in result)
       MessageBox.Show(y, "Selected Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

For files and folders you need to use the CommonOpenFileDialog included with the WinAPI, the particular class is here.

Leave a Comment