protected void ExportToPDF(object sender, EventArgs e) { using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { DetailsView1.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); using (MemoryStream memoryStream = new MemoryStream()) { PdfWriter.GetInstance(pdfDoc, memoryStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); string too = string.Concat(DropDownList1.SelectedValue, "@med.sa"); string from1 = String.Concat(Label1.Text, "@med.sa"); string pass = Session["Pass"].ToString(); MailMessage mm = new MailMessage(from1,too); mm.Subject = "GridView Exported PDF"; mm.Body = "GridView Exported PDF Attachment"; mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "GridViewPDF.pdf")); mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "100.43.100.101"; smtp.EnableSsl = true; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(); NetworkCred.UserName = from1; NetworkCred.Password = pass; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 30; smtp.Send(mm); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)