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

后端 未结 3 852
攒了一身酷
攒了一身酷 2020-12-11 01:41

I have posted - How to use OpenFileDialog to select a folder?, I couldn\'t find the correct answer. So, I have changed my question.

I want to customize OpenFileDialo

3条回答
  •  悲&欢浪女
    2020-12-11 02:13

    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.

提交回复
热议问题