Hi
I have a folder which contains text files . Guide me in sorting the files according to date and time.
Kritika
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 11, 2013, 10:43 PM EDT
var files = dinfo.GetFiles("*.*").OrderByDescending(s => s.LastWriteTime).ToList();
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 11, 2013, 9:47 PM EDT
http://stackoverflow.com/questions/9001544/sorting-a-listfileinfo-by-creation-date-c-sharp
http://stackoverflow.com/questions/5049202/sorting-files-by-date
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 11, 2013, 9:52 PM EDT
You can do by using lambda expression like this
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 11, 2013, 10:08 PM EDT
What will be the namespace for DirectoryInfo
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 11, 2013, 10:13 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 11, 2013, 10:29 PM EDT
The code send by you is not working.
Kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 11, 2013, 10:32 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 11, 2013, 10:34 PM EDT
My code looks like:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string path = "D:\\Test";
DirectoryInfo dinfo = new DirectoryInfo(path);
var files = dinfo.GetFiles("*.*").OrderByDescending(s => s.LastWriteTime).ToList();
}
}
Its not showing anything and also files remain unsorted
kritika
kritika RanaRank #7,001 · 251 reputationPosted Aug 11, 2013, 11:10 PM EDT
Thanks for the guidance . The code you send is working now.
kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 11, 2013, 11:28 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 11, 2013, 11:46 PM EDT
Now I want the text of some files are to be written on MS outlook express. How to write the code for it in C#
Kritika