Skip to content

Browsing files in a folder

antti poutiainen

Asked Mar 28, 2008, 1:50 PM EDT1 answer
Share
LinkedInX
Greetings!

I am really new to C#, and fairly new to programming itself aswell. Although i've got to know C# quite a bit now, but mostly on the console program side of it. Now i'd like to get introduced to the windows environment better. I made myself a little picture / photo album browser, where i choose a file with OpenFileDialog and it is shown in a picturebox - Ok, this works like a charm. But it would be so much easier to browse pictures as a bunch, not by opening them one at a time.

So my problem is that i would love to do this so that i could choose a folder (with FolderBrowserDialog), and then i could browse through the images in that chosen folder, using puttons like previous image and next image. How is this done? Anykind of help / hint for a solution is greatly appreciated.

Thanks in advance!
skinex

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You can load an array (ListDictionary) with a list of files with a certain extension from the folder, so say *.jpeg, or *.gif you can do this like:

    I think you will need the System.IO;

                DirectoryInfo dir = new DirectoryInfo(@"C:\dir\images");
                FileInfo[] jpgfiles = dir.GetFiles("*.jpg");
                int position = jpgfiles.Length;

                foreach( FileInfo f in jpgfiles)
                {
                    _name_list.Add(position, f.Name);
                    position--;
                }

    then you can use buttons to browse through the list.
    0