I'm looking for some suggestions on how to approach this windows form based application I'm in the very beginning stages of writing. Bare in mind Im still at the Hello World level of C#.

How should I populate a listbox with mock names for all jpegs in a folder whlie storing additional data about each jpeg. (data not included in the file properties)

for instance a folder containing:
DSC-001.jpg
DSC-002.jpg

Would populate a listbox as:
image1
image2

Each image will generate an entry in an array or table which will be modified later in the program:
image1 / DSC-001.jpg / some int values / string values.

Should this data be stored in an array? or an sql database?

Thanks, Trev.

Should this data be stored in an array? or an sql database?

What you have there is meta data. The best way to get started from your level is to think about that data as an object.

So, each picture will be an object with properties. Size, location on disk, photographer, caption etc will all be properties of this picture object.

1) Create a class for your picture object and properties for each of the meta data you want to store.

Now that you have your objects in place, you can think about persisting them. You can serialize them to the hard disk using the Serialization classes in .NET or save them to a database. Which you choose depends on how much data, who else (or what programs) may also need access to your data, etc.

I hope that helps you start thinking on the right track.

When I was at the Hello World stage of coding C# I had no idea of how to create a class for each object, so just in case you struggle wiht the concept that agrothe has talked about above, I've written you a basic layout for the class you could use.

public class ImageFile
{
	private string name;
	private int size;
	private string fullPath;
	
	public ImageFile() { }
	
	public ImageFile(string name)
	{
		this.name = name;
	}
	
	public string Name
	{
		get { return this.name; }
		set { this.name = value; }
	}
	
	public int Size
	{
		get { return this.size; }
		set { this.size = value; }
	}
	
	public string FullPath
	{
		get { return this.fullPath; }
		set { this.fullPath = value; }
	}
}

You could have an array of ImageFile's to save each of them and keep all the info together and well organised. Here's a little example:

List<ImageFile> imageFiles = new List<ImageFile>();

...

ImageFile imageFile = new ImageFile();
imageFile.Name = fileName;
imageFile.Size = fileSize;
imageFile.FullPath = filePath;
imageFiles.Add(imageFile);

Is it possible to have these objects created dynamically?

Speaking in code "For each Jpeg in the directory > create an object > assign the object a unique name (imageFile + i++) > assign the file name/location > assign some more data"

Is it possible to have these objects created dynamically?

Speaking in code "For each Jpeg in the directory > create an object > assign the object a unique name (imageFile + i++) > assign the file name/location > assign some more data"

Use this to iterate through files in a directory.

string MyDirectory = "C:\\";
string MyString = "My Files: ";

try{
     string [] MyFiles = Directory.GetFiles( MyDirectory, "*.jpg", SearchOption.TopDirectoryOnly );

     foreach( string MyFile in MyFiles )
     {
          MyString = MyString + MyFile + "; ";
     }
          MessageBox.Show( MyString );
     }
catch(Exception MyError){
     MessageBox.Show("Error reading file: "+ MyError.Message);
}

from: http://www.ehow.com/how_5160227_loop-getfiles-microsoft-visual-sharp.html#ixzz13ZiSh7Vz

Edited 6 Years Ago by agrothe: formatting

Thanks for your help! I'm finding this example very useful and will attempt to apply it to my project.

I just want to make sure I have a proper understanding of the code;

The top half is declaring the class and variables. get and set are bassically assigning null values. The first line of the second block of code declares a list class. the " ... " represent where the loop mechanism would be. new ImageFile creates a new object and the remaining lines; (after the equal signs) assign the properties.

Thanks for your help! I'm finding this example very useful and will attempt to apply it to my project.

I just want to make sure I have a proper understanding of the code;

The top half is declaring the class and variables. get and set are bassically assigning null values. The first line of the second block of code declares a list class. the " ... " represent where the loop mechanism would be. new ImageFile creates a new object and the remaining lines; (after the equal signs) assign the properties.

This simple project puts the pieces together for you. I commented pretty much every line to explain how things work.

Comments
Very helpfull for the op.
This article has been dead for over six months. Start a new discussion instead.