I'm trying to sort the data in lambda expression in the following case.
if (Directory.Exists(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ErrorLogPath"].ToString())))
{
string path = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["ErrorLogPath"].ToString());
// a.Select(p => Path.GetFileNameWithoutExtension(p));
var a = Directory.GetFiles(path);
if (a != null)
{
Session["gvData"] = a.ToList();
BindDataToGrid();
}
}
In var
a
i get list of complete path of files like
c:\\logfiles\\01022012.txt.
How can I get var
a
sorted on basis of 01022012
I tried
var a = Directory.GetFiles(path).OrderBy(p=>Path.GetFileNameWithoutExtension(p));
but not working. Is there any thing am I doing wrong?
Getting result as
"C:\\LogFiles\\01112012.txt"
"C:\\LogFiles\\08102012.txt"
"C:\\LogFiles\\14092012.txt"
"C:\\LogFiles\\15102012.txt"
"C:\\LogFiles\\17102012.txt"
"C:\\LogFiles\\19092012.txt"
Expected is
"C:\\LogFiles\\14092012.txt"
"C:\\LogFiles\\19092012.txt"
"C:\\LogFiles\\08102012.txt"
"C:\\LogFiles\\15102012.txt"
"C:\\LogFiles\\17102012.txt"
"C:\\LogFiles\\01112012.txt"