I need to have an open file dialog for 1000 file types (*.000 - *.999). But adding it to the filter, the dialog gets really slow on choosing file types. Is there anything I can do to speed this up?
string text;
for (int i = 0; i <= 999; i++)
{
text.Append("*." + i.ToString("000") + "; ");
}
string textWithoutLastSemicolumn = text.ToString().Substring(0, text.ToString().Length - 2);
dialog.Filter = "Files (" + textWithoutLastSemicolumn + ")|" + textWithoutLastSemicolumn;
If you're stuck with those extensions, I can see 2 possible solutions. Either accept this rather fast, but not 100% correct solution:
ofd.Filter = "Supported extensions | *.0??;*.1??;*.2??;*.3??;*.4??;*.5??;*.6??;*.7??;*.8??;*.9??";
This will accept all of your extensions, but also values such as .0a1, .99y, and so on. If you know those file extensions will not be a problem in your situation, this might be a good alternative.
A different solution might be to make your own implementation of the OpenFileDialog with support for regular expressions as a filter. This would be the best solution performance and security-wise, but I don't know how hard it'll be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With