I here by attach the file open it in wordpad on the 6th line there is a word SGH . I want to make sub Like APU performance report VT- SGH. This highlighted text is different for different file. The code should pick that word from the file and suffix it withe APU performance report VT-SGH.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 2:02 AM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 8:04 PM EDT
Please share the file format.
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 8:15 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 8:19 PM EDT
49101 VT-SGH B737-800 130805 XXXXXX VAAH. VIDP. 0132 ROJ807
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 8:25 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 8:33 PM EDT
string subject="";
string line;
break;
private string GetSubject(string fileContent)
{
var tempArray = temp.Split(' ');
var subject = tempArray[1];
return subject;
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 8:52 PM EDT
while ((line = file.ReadLine()) != null)
{
if (line.Contains("49101"))
{
subject = GetSubject(line);
break;
}
}
private string GetSubject(string fileContent)
{
var tempArray = temp.Split(' ');
var subject = tempArray[1];
return subject;
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 8:57 PM EDT
string subject="";
string line;
break;
private string GetSubject(string fileContent)
{
var tempArray = fileContent.Split(' ');
var subject = tempArray[1];
return subject;
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 9:17 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 9:24 PM EDT
string subject="";
string line;
break;
SendMail(textFile.ReadToEnd(),subject );
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 9:29 PM EDT
My code is as
private void button1_Click_1(object sender, EventArgs e)
{
string path = @"D:\Test";
DirectoryInfo dinfo = new DirectoryInfo(path);
var files = dinfo.EnumerateFiles("R66*", SearchOption.AllDirectories);
//string path = @"D:\vikas";
//DirectoryInfo dinfo = new DirectoryInfo(path);
var file = dinfo.GetFiles("R66*").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))
{
string subject = "";
string line;
while ((line = textFile.ReadLine()) != null)
{
if (line.Contains("49101"))
{
subject = GetSubject(line);
break;
}
}
//SendMail(textFile.ReadToEnd());
SendMail1(textFile.ReadToEnd(),subject );
}
}
MessageBox.Show("Email Send Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Mail Not Send Check for error", ex.ToString());
}
}
private string GetSubject(string fileContent)
{
var tempArray = fileContent . Split(' ');
var subject = tempArray[1];
return subject;
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 9:32 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 9:34 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 9:36 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 9:38 PM EDT
SendMail1(textFile.ReadToEnd(),subject );
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 9:53 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 9:57 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 10:02 PM EDT
{
MailMessage mailMessage = new MailMessage();
// mailMessage.From = new MailAddress("[email protected]", "Kritika");
mailMessage.From = new MailAddress("[email protected]", "kritika");
mailMessage.To.Add("[email protected]");
// mailMessage.To.Add("[email protected]");
// mailMessage.To.Add("[email protected]");
mailMessage.Subject = "Spicejet-APU Shutdown Report VT- " +subject;
mailMessage.IsBodyHtml = true;
mailMessage.Body = fileContent + "
";
using (SmtpClient mailbox = new SmtpClient("smtp.gmail.com", 587))
{
mailbox.Credentials = new NetworkCredential("[email protected]", "pawd");
// mailbox.Credentials = new NetworkCredential("[email protected]", "abc");
mailbox.EnableSsl = true;
mailbox.Send(mailMessage);
}
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 10:05 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 10:08 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 10:09 PM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 21, 2013, 10:54 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 21, 2013, 11:38 PM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 22, 2013, 1:32 AM EDT
03960 09201 08664
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 1:34 AM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 22, 2013, 1:38 AM EDT
{
string path = @"D:\Test";
DirectoryInfo dinfo = new DirectoryInfo(path);
var files = dinfo.EnumerateFiles("R66*", SearchOption.AllDirectories).OrderBy(s => s.LastWriteTime);
//string path = @"D:\vikas";
//DirectoryInfo dinfo = new DirectoryInfo(path);
// var file = dinfo.GetFiles("R66*").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))
{
string subject = "";
string line;
while ((line = textFile.ReadLine()) != null)
{
if (line.Contains("49101"))
{
subject = GetSubject(line);
break;
}
}
SendMail1(textFile.ReadToEnd(),subject);
}
}
MessageBox.Show("Email Send Successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private string GetSubject(string fileContent)
{
var tempArray = fileContent.Split(' ');
var subject = tempArray[1];
return subject;
}
private void SendMail1(string fileContent,string sub)
{
MailMessage mailMessage = new MailMessage();
// mailMessage.From = new MailAddress("[email protected]", "Kritika");
mailMessage.From = new MailAddress("[email protected]", "kritika");
mailMessage.To.Add("[email protected]");
// mailMessage.To.Add("[email protected]");
// mailMessage.To.Add("[email protected]");
mailMessage.Subject = "Spicejet-APU Shutdown Report " +sub ;
mailMessage.IsBodyHtml = true;
mailMessage.Body = fileContent + "
";
using (SmtpClient mailbox = new SmtpClient("smtp.gmail.com", 587))
{
mailbox.Credentials = new NetworkCredential("[email protected]", "paswd");
// mailbox.Credentials = new NetworkCredential("[email protected]", "abc");
mailbox.EnableSsl = true;
mailbox.Send(mailMessage);
}
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 1:49 AM EDT
Regards,
Iftikar
kritika RanaRank #7,001 · 251 reputationPosted Aug 22, 2013, 1:55 AM EDT
kritika RanaRank #7,001 · 251 reputationPosted Aug 22, 2013, 2:04 AM EDT
Thanks a lot
Kritika
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 22, 2013, 2:09 AM EDT
Regards,
Iftikar
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts