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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -