Hi
I have some files in which date and time is mentioned. I want to sort the files .In very first line of the file date and time is mentioned. Files must be sorted accordingly.
Assist me for the proper code.
regards
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 attend4days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 9:25 PM EDT
I think you have done this in your last post.
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 9:30 PM EDT
Again I have some new queries........
As my program is working properly but I want to sort the files according to date and time mentioned in the very first line of the files.
If possible then guide me completing the project.
I hereby attach sample files for your reference
Regards
Kritika
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 9:33 PM EDT
When you open the file in wordpad you will find in very first line date and time is mentioned.
I want the files to be sorted according to that date and time.
Hope you understand my query.
Regards
Kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 9:34 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 9:38 PM EDT
If you open the file which I have send u as attachment, date and time is mentioned in very first line of the file . I want to sort according to that date and time not as system date and time
Kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 9:39 PM EDT
and which one need to check?
R49-4002.049³ 13AUG14³ 11:26:52³ 13AUG14³ 11:26:49³ APU-PERF.VDR
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 9:42 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 9:43 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 9:47 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 9:48 PM EDT
R49-4002.049³ 13AUG14³ 11:26:52³ 13AUG14³ 11:26:49³ APU-PERF.VDR
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 9:52 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 9:53 PM EDT
the highlighted value
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 9:56 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 10:01 PM EDT
private void button7_Click(object sender, EventArgs e)
{
string path = @"D:\vikas";
DirectoryInfo dinfo = new DirectoryInfo(path);
var files = dinfo.GetFiles("*").OrderBy(s => s.LastWriteTime).ToList();
StringBuilder sb = new StringBuilder();
try
{
foreach (var fileInfo in files)
{
var filePath = fileInfo.FullName;
using (var textFile = File.OpenText(filePath))
{
SendMail(textFile.ReadToEnd());
}
}
MessageBox.Show("Email Send Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Mail Not Send Check for error",ex.ToString ());
}
}
private void SendMail(string fileContent)
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("[email protected]", "Kritika");
mailMessage.To.Add("[email protected]");
mailMessage.Subject = "Test Subject";
mailMessage.IsBodyHtml = true;
mailMessage.Body = fileContent+"
";
using (SmtpClient mailbox = new SmtpClient("smtp.gmail.com", 587))
{
mailbox.Credentials = new NetworkCredential("[email protected]", "mrsseema");
mailbox.EnableSsl = true;
mailbox.Send(mailMessage);
}
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 10:06 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 10:07 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 10:24 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 10:26 PM EDT
";
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 10:26 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 10:28 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 10:46 PM EDT
private static DateTime GetDateValue(string fileContent, string fileName)
{
var temp = fileContent.Replace(fileName, string.Empty);
temp = temp.Replace("APU-PERF.VDR", string.Empty);
temp = temp.Replace("?", string.Empty);
temp = temp.Trim();
var tempArray = temp.Split(' ');
var tempDate = tempArray[2];
var tempTime = tempArray[3];
var tempDay = Convert.ToInt16(temp.Substring(5, 2));
var tempMonth = Convert.ToInt32(GetMonth(tempDate.Substring(2, 3)));
var tempYear = Convert.ToInt32(tempDate.Substring(0, 2));
var tempTimeArray = tempTime.Split(':');
var tempHr = Convert.ToInt16(tempTimeArray[0]);
var tempMint = Convert.ToInt16(tempTimeArray[1]);
var tempSecond = Convert.ToInt16(tempTimeArray[2]);
var dt = new DateTime(tempDay, tempMonth, tempYear, tempHr, tempMint, tempSecond);
return dt;
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 10:51 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 11:01 PM EDT
try
{
foreach (var fileInfo1 in resultFiles)
{
var filePath1 = fileInfo1.FullName;
using (var textFile = File.OpenText(filePath1))
{
SendMail(textFile.ReadToEnd());
}
}
MessageBox.Show("Email Send Successfully");
}
catch (Exception ex)
{
MessageBox.Show( ex.ToString());
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 11:04 PM EDT
var filePath = fileInfo.FilePath;
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 11:09 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 11:11 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 11:14 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 11:16 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 11:31 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 11:47 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 15, 2013, 11:52 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 15, 2013, 11:54 PM EDT
Thanks
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 16, 2013, 12:14 AM EDT
Regards,
Iftikar