-1

I have this line:

imageList = Directory.GetFiles(@"e:\webbrowserimages\", "*.bmp").ToList();

This is a List

But i want now just one string variable single variable not a list that will contain the last saved image file on the hard disk.

If for example i have 10 images on the hard disk and the first one is: Image0.bmp then Image1.bmp so the string variable will contain Image10.bmp And then if on my hard disk there are 24 images then the variable string should contain Image24.bmp

Simon Gamlieli
  • 119
  • 1
  • 18

1 Answers1

4

You can do this to get the latest bitmap file in the direcotry,

var directory = new DirectoryInfo(@"e:\webbrowserimages\");

var myFile = (from f in directory.GetFiles("*.bmp")                   
                orderby f.LastWriteTime descending
                select f).First();

Unless no other parameter is available better not relying on file name in filtering latest image.

Hari Prasad
  • 16,716
  • 4
  • 21
  • 35