Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenFileDialog with many extensions

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;
like image 323
user2332131 Avatar asked Sep 28 '22 03:09

user2332131


1 Answers

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.

like image 127
Saragis Avatar answered Oct 04 '22 19:10

Saragis