Search code examples
c#limitopenfiledialog

Does OpenFileDialog.Filenames have a limit?


I have a small helper app that I use to "inject" scripts into html pages.

I have an openfiledialog promt and i select all the html files in that directory (1403 files) and no matter what i do i see that OFD.filenames.count = 776

is there a limit?

thanks

OpenFileDialog OFD = new OpenFileDialog();
            OFD.Multiselect = true;
            OFD.Filter = "HTML Files (*.htm*)|*.HTM*|" +
          "All files (*.*)|*.*";

            if (OFD.ShowDialog() == DialogResult.OK)
            {
                progressBar1.Maximum = OFD.FileNames.Count();
                foreach (string s in OFD.FileNames)
                {
                    Console.WriteLine(s);
                    AddAnalytics(s);
                    progressBar1.Value++;
                }
                MessageBox.Show(string.Format("Done! \r\n {0} files completed",progressBar1.Value));
                progressBar1.Value = 0;
            }

Solution

  • The OpenFileDialog will only use the first 256 characters in the 'file name' field. The field itself displays more, but it ignores anything after the 256 characters.

    I believe in your case the missing files are listed after the 256 character mark.