I need to sort files based on the date and time they were last created or modified and show the latest added file in the first. Basically the asp.net form is for uploading the files on the webserver and after uploading, by default the files get organised on the basis of the its name or I should say in alphabetic order. So, can any one help me sort and organise it on the basis of the time it was uploaded.
protected void getFiles()
{
System.Text.StringBuilder sbld = new System.Text.StringBuilder();
if (Directory.Exists(Server.MapPath("~/Package_Image/")))
{
DirectoryInfo dirMail = new DirectoryInfo(Server.MapPath("~/Package_Image/"));
FileInfo[] DefaultFiles = dirMail.GetFiles();
foreach (FileInfo fileDir in DefaultFiles)
{
if (fileDir.Extension.ToLower() == ".jpg" || fileDir.Extension.ToLower() == ".gif" || fileDir.Extension.ToLower() == ".png" || fileDir.Extension.ToLower() == ".jpeg" || fileDir.Extension.ToLower() == ".bmp")
{
// need sorting on the basis of date-time, it was created or uploaded.
sbld.Append("<div class='itemBox'><table width='100%'><tr><td height='160'><img width='200' src='../Package_Image/" + fileDir.Name + "'></img></td></tr></table></div>");
}
}
Literal1.Text = (sbld.ToString());
}
}
The sorting might be using C#, that will be done by the server itself, or if possible can I do it with javascript or jquery, so that it can be processed at the client itself.