Search code examples
c#visual-studio-2010textboxopenfiledialog

open file dialog return multiple file names (Visual Basic 2010 C#)


How to make a OpenFileDialog1 object return multiple paths of the selected files to a multi-line textbox?


Solution

  • I've created some code for you to use:

    private void SomeMethod()
    {
        string[] lines = GetFileNames();
    
        if (lines != null)
            textBox1.Lines = lines;
    }
    
    private string[] GetFileNames()
    {
        var dialog = new OpenFileDialog()
        {
            Multiselect = true
        };
    
        if (dialog.ShowDialog() == DialogResult.OK)
            return dialog.FileNames;
        else
            return null;
    }
    

    I hope it helps.