Get file extensions to populate into a ComboBox in C# -
so have folder imagens in many extensions .ico
, .png
, .jpg
, etc. , i've populated combobox
using code:
string caminho = @"c:\users\user1\desktop\test\"; directoryinfo dir = new directoryinfo(caminho); fileinfo[] fi = dir.getfiles(); foreach (var ficheiro in fi) { string caminhof = caminho + ficheiro.tostring(); string extension = path.getextension(caminhof); combobox1.items.add(extension); }
the code getting existing extensions in path , put on combobox
, displays this:
.ico .ico .ico .png .png .jpg .jpg
and want display each 1 of existing extensions grouping them.
could me that?
you can file extension fileinfo
. can use linq distinct()
unique extensions.
string caminho = @"c:\users\user1\desktop\test\"; directoryinfo dir = new directoryinfo(caminho); var extensions = dir.getfiles().select(fi => fi.extension).distinct(); foreach (var extension in extensions) { combobox1.items.add(extension); }
Comments
Post a Comment