Get file extensions to populate into a ComboBox in C#

Viewed 324

So I have a folder with some imagens in many extensions like .ico, .png, .jpg, etc. and I've populated it into a comboBox using this 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 is getting all the existing extensions in this path and put it on the comboBox, but it displays like this:

.ico
.ico
.ico
.png
.png
.jpg
.jpg

and I want to simply display each one of the existing extensions like grouping them.

Could you help me with that?

4 Answers
Related