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

后端 未结 3 851
攒了一身酷
攒了一身酷 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:00

    You might not get a built in .Net control like that. Definitely the OpenFileDialog can not function as both File as well as Folder browser. You have two choices go for a third party tool like the one you found second make your own control. Surprisingly you might not find creating a very simple version of your own control very difficult.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-11 02:14

    Try this:

    openFileDialog.Multiselect = true;
    
    0 讨论(0)
提交回复
热议问题