tags:

views:

56

answers:

1

I am trying to select existing images from a directory. The image files are being renamed dynamically when they are created but the format they currently have cannot be changed. This is an example.

client_2010_10_23_001.jpg

Essentially, the images are names according to upload time and incremented. Perhaps split the file name into an array and select that way? I think that could be the right direction but I'm having trouble conceiving the approach.

Thanks!

+6  A: 

I think this will do it:

var allImages = System.IO.Directory.GetFiles("C:\\", "*.jpg");
var random = new Random();
var randomImage = allImages[random.Next(allImages.Length)];
Onkelborg
That was quick, thanks!!
John