I remember that I have to use the directoryinfo object to pull the images from the folder but then i'm getting stuck. Could someone help me please?
Creating a Windows Application to view Images
Hi, I have images from a horse show that I was recently a part of and wanted to create a C# Windows Application that will allow me to do this. I wanted to put the images into a list box and but I wanted to pick them up from my images folder on the computer. I'm using VS 2010 and I've done some programming at school but just need a little help if anyone would be so kind?


FroglegRank #1,020 · 1.9K reputationPosted Oct 10, 2013, 3:13 PM EDT
using System.IO;
private void bttnOpen_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { textBox1.Text = folderBrowserDialog1.SelectedPath; getPics(folderBrowserDialog1.SelectedPath);// getl list of files } } public void getPics(string fPath) { foreach (string file in Directory.GetFiles(fPath)) { if (checkIfimage(file))//check if file is image { listBox1.Items.Add(file); } } } public bool checkIfimage(string fname) { bool isImage = false; string extension = Path.GetExtension(fname).ToLower(); if (extension == ".jpg" | extension == ".png"|extension==".bmp") { isImage = true; } return isImage; }ashleyturnier18 reputationPosted Oct 10, 2013, 10:10 PM EDT
Jade Collinton8 reputationPosted Oct 12, 2013, 2:25 AM EDT
Thanks for the reply,
When I'm trying this i get the error 'Error1The name 'folderBrowserDialog1' does not exist in the current context' and it doesn't pick up the images from my C:\Pictures\Images folder either. The listbox is just empty. The names that I entered into the listbox are there but when I select one and go to open nothing happens.
Below is what my form looks like but nothing happens when I click on any of the options.
Sunny SharmaRank #223 · 11.1K reputationPosted Oct 12, 2013, 4:18 AM EDT
Here you go, I've created a sample application for you.
You're free to download, use and study for yourself.
Happy Learning :)
FroglegRank #1,020 · 1.9K reputationPosted Oct 12, 2013, 10:16 AM EDT
Note - you will have to proportion the picturebox to suit images