I am trying to send GridView to mail attachment(as excel). Everything works fine,but the problem is with dates in generated excel sheet.
I have dates in GridView header row like 11-08,12-08,13-08,14-08...
Problem is,the first two are showing as 8-Nov,08-Dec in generated excel sheet,other are showing as expected 13-08,14-08....
The code i used is as follows(Gridview as mail attachment)
StringWriter stw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(stw);
GridView1.RenderControl(hw);
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.To.Add(new MailAddress("abc"));
mail.Subject = "report";
System.Text.Encoding Enc = System.Text.Encoding.ASCII;
byte[] mBArray = Enc.GetBytes(stw.ToString());
System.IO.MemoryStream mAtt = new System.IO.MemoryStream(mBArray, false);
mail.Attachments.Add(new Attachment(mAtt, "def.xls"));
mail.Body = "Please find the attached document for the date" + DateTime.Now.ToString("dd-MMM-yyyy");
SmtpClient smtp = new SmtpClient();
mail.From = new MailAddress(efg, hij);
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(***,***);
smtp.EnableSsl = true;
smtp.Send(mail);
Why this dates are being modified this way? Any help please?