try { if (Session["Projectname"] != null && Session["Projectname"].ToString() != string.Empty) { string Projname = Session["Projectname"].ToString(); System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); design.RenderControl(htmlWrite); string strBuilder = stringWrite.ToString(); string strPath = Request.PhysicalApplicationPath + "\\Temp\\WeeklyReport of " + Projname + ".docx"; LblNoteMsg.Text = strPath; if (File.Exists(strPath)) { var counter = 1; strPath = strPath.Replace(".docx", " (" + counter + ").docx"); while (File.Exists(strPath)) { strPath = strPath.Replace("(" + counter + ").docx", "(" + (counter + 1) + ").docx"); counter++; } } using (var fStream = File.Create(strPath)) { fStream.Close(); fStream.Dispose(); } using(StreamWriter sWriter = new StreamWriter(strPath)) { sWriter.Write(strBuilder); sWriter.Close(); sWriter.Dispose(); Response.Clear(); } DateTime input = DateTime.Now; int delta = DayOfWeek.Monday - input.DayOfWeek; DateTime dats = DateTime.Now.AddDays(delta); //this week DateTime monday = input.AddDays(delta); string MonDate = monday.ToShortDateString(); DateTime sat = monday.AddDays(5); string SatDate = sat.ToShortDateString(); StreamReader r = new StreamReader(Server.MapPath("~/WeeklyMail.txt")); string body = r.ReadToEnd(); MailMessage Msg = new MailMessage(); string MailId = txtMailId.Text; foreach (string ss in MailId.Split(",".ToCharArray())) { if (string.IsNullOrEmpty(ss) == false) { Msg.To.Add(new MailAddress(ss)); } } Msg.Bcc.Add(new MailAddress("support@sunlightit.com")); body = body.Replace("<%MonDate%>", MonDate); body = body.Replace("<%SatDate%>", SatDate); Msg.Subject = "Weekly status Report of " + Projname + "," + DateTime.Now.ToShortDateString() + ""; Msg.Body = body; Msg.IsBodyHtml = true; Msg.Attachments.Add(new Attachment(strPath)); SmtpClient MailServer = new SmtpClient(); try { MailServer.Send(Msg); string reply = (Msg.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnSuccess).ToString(); if (reply == "OnSuccess") { txtMailId.Text = ""; tblMail.Visible = false; lblMsg.ForeColor = System.Drawing.Color.Green; lblMsg.Text = "Mail has send succesfully"; } else { lblMsg.ForeColor = System.Drawing.Color.Red; lblMsg.Text = "Mail delivery unsuccessfull"; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)