0

Basically, I have a music folder. And inside the music folder, it has album folders. Each album folders has its own thumbnail.png inside.

I have the folder browser to pop up and I can select the music folder. When I select the music folder, The album folders show up in the listview but I haven't been able to add the thumbnail image as the icon for the album folder.

This is the code I am working with.

private void button1_Click(object sender, EventArgs e)
{
    folderBrowserDialog1.Description = "Choose the Music folder.";
    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
    {
        listView1.Items.Clear();
        string[] dirs = Directory.GetDirectories(folderBrowserDialog1.SelectedPath);

        foreach(string file in dirs)
        {
            listView1.Items.Add(Path.GetFileNameWithoutExtension(file));
        }
    }
}

I tried to use loops that will search the inside of each album folder for the "thumbnail.png" file and then index it and add it into the imagecollection or something. But nothing I tried work so any help or links on how these work will be greatly appreciated.

I am posting this at 5 am. I have been up all day and night but I still can't figure out how to do this. This is probably going to be hard to understand/read so I'll try to edit it when I wake up, sorry in advance.

Ka Res
  • 311
  • 2
  • 3
  • 17

1 Answers1

0
private void button1_Click(object sender, EventArgs e)
    {
        var imageList = new ImageList();
        if (folderBrowserDialog1.ShowDialog()==DialogResult.OK)
        {
            var directories = Directory.GetDirectories(folderBrowserDialog1.SelectedPath);
            foreach (string item in directories)
            {
                FileInfo file = new FileInfo(item);                    
                imageList.Images.Add("Key" + file.Name, Image.FromFile(file.ToString() + @"\thumbnail.png"));
                listView1.LargeImageList = imageList;
                var listViewItem = listView1.Items.Add(file.Name);
                listViewItem.ImageKey = "Key" + file.Name;

            }

        }
    }
Hasan Jafarov
  • 628
  • 6
  • 16
  • Thank you. This is exactly what I was looking for. – Marco Alba Jan 13 '18 at 01:59
  • 1
    @MarcoAlba But the code specified in this "answer" does also not show the folder icons in the `FolderBrowserDialog`. It just iterates through the directory, chosen by the dialog and adds the thumbnails to an `ImageList`. From my perspective, this is not the answer. – Christian Junk Feb 24 '18 at 15:21