Opening multiple files (OpenFileDialog, C#)

前端 未结 2 513
清酒与你
清酒与你 2020-12-05 04:55

I\'m trying to open multiple files at once with the OpenFileDialog, using FileNames instead of FileName. But I cannot see any examples

2条回答
  •  感情败类
    2020-12-05 05:04

    You can use this method for text files:

    OpenFileDialog open = new OpenFileDialog();
    open.Filter = "All Files *.txt | *.txt";
    open.Multiselect = true;
    open.Title = "Open Text Files";
    
    if (open.ShowDialog() == DialogResult.OK)
    {
        foreach (String file in open.FileNames)
        {    
             string temp = YourRichTextBox.Text;
    
             YourRichTextBox.LoadFile(file, RichTextBoxStreamType.PlainText);
    
             YourRichTextBox.Text += temp;
        }
    }
    

提交回复
热议问题