So a long time ago, I had written some code to automatically display images from folders. So on my personal site via login, family members can see pictures, and all I have to do is just upload a folder of images. Thumbnails and paging, etc. etc. is created automatically. It's nice because I can just dump pictures into a folder and forget about it. No coding, no hassle, no fuss.
The big problem I ran into was that there is no way using the FileSystemInfo object to sort by date. I think that is crazy. So I had to use the IComparer interface to do the comparison my self.
System.Collections.IComparer dateComparer = new DateComparer();
System.IO.DirectoryInfo mDir = new System.IO.DirectoryInfo(System.Configuration.ConfigurationSettings.AppSettings["KatherineImages"].ToString()); System.IO.FileSystemInfo[] mFiles = mDir.GetFiles("*.jpg"); Array.Sort(mFiles, dateComparer);
private sealed class DateComparer : System.Collections.IComparer { public int Compare(object info1, object info2) { System.IO.FileInfo fileInfo1 = info1 as System.IO.FileInfo; System.IO.FileInfo fileInfo2 = info2 as System.IO.FileInfo;
DateTime Date1 = fileInfo1 == null ? System.Convert.ToDateTime(System.Data.SqlTypes.SqlDateTime.Null) : fileInfo1.LastWriteTime; DateTime Date2 = fileInfo2 == null ? System.Convert.ToDateTime(System.Data.SqlTypes.SqlDateTime.Null) : fileInfo2.LastWriteTime;
if (Date1 > Date2) return 1; if (Date1 < Date2) return - 1; return 0; } }
|
This allows me to sort the files by date, so when uploading images from a digital camera session, people are not seeing the last images first. They are seeing the images in the date/time order they were taken.