I'm trying to find a decent way to sort an array of strings which contains dates by dates descending.
For instance my list contains this :
page1.aspx_12-05-2013.aspx
page2.aspx_12-04-2010.aspx
page1.aspx_17-09-2014.aspx
page1.aspx_11-01-2013.aspx
I already managed to sort the dates in the strings but i don't know how to do it by keeping the text before This is how i do to sort the dates:
List<FileInfo> fi = new List<FileInfo>();
fi = System.IO.Directory.GetFiles(@"C:\Users\arn\Desktop\testlatestpr")
.Select(x => new System.IO.FileInfo(x))
.ToList();
List<string> listofdates = new List<string>();
foreach (var x in fi)
{
Console.WriteLine(x.Name.Substring(x.Name.Length - 15, 10).ToString());
listofdates.Add(x.Name.Substring(x.Name.Length - 15, 10).ToString());
}
var orderedList = listofdates.OrderByDescending(x => DateTime.Parse(x)).ToList();
Thanks for your help