Home > OS >  C# Desktop Application multi image select
C# Desktop Application multi image select

Time:09-07

I have this logic and I set dialog.Multiselect = true, so I can select multi images, but the problem is that I get only the first image path. Do you know how to get and the other images path, not only first

private void flatButton4_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Select Valid Document(*.png; *.jpeg; *.jpg)|*.png; *.jpeg; *.jpg";
            dialog.Multiselect = true;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                String path = dialog.FileName;
                using (StreamReader reader = new StreamReader(new FileStream(path, FileMode.Open), new UTF8Encoding()))
                {
                    textBox12.Text = path;
                }
            }
        }

CodePudding user response:

The paths are in the OpenFileDialog.FileNames array.

Try this:

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Select Valid Document(*.png; *.jpeg; *.jpg)|*.png; *.jpeg; *.jpg";
dialog.Multiselect = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
    foreach (string fileName in dialog.FileNames)
    {
        // do something with path
    }
}       
  • Related