protected void btnExportSafetyPDF_Click(object sender, ImageClickEventArgs e) { GridSafety.AllowPaging = false; GridSafety.DataBind(); Response.Clear(); Response.Buffer = true; Response.ClearContent(); Response.ClearHeaders(); Response.Charset = ""; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=SafetyReport " + DateTime.Now.ToShortDateString() + ".pdf"); GridSafety.GridLines = GridLines.Horizontal; GridSafety.HeaderStyle.Font.Bold = true; GridSafety.HeaderStyle.ForeColor = System.Drawing.Color.DarkBlue; GridSafety.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); GridSafety.AllowPaging = true; GridSafety.DataBind(); }
protected void btnExportSafetyExcel_Click(object sender, ImageClickEventArgs e) { GridSafety.AllowPaging = false; GridSafety.DataBind(); Response.Clear(); Response.Buffer = true; Response.ClearContent(); Response.ClearHeaders(); Response.Charset = ""; string FileName = "SafetyReport " + DateTime.Now.ToShortDateString() + ".xls"; StringWriter strwritter = new StringWriter(); HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName); GridSafety.GridLines = GridLines.Both; GridSafety.HeaderStyle.Font.Bold = true; GridSafety.RenderControl(htmltextwrtter); Response.Write(strwritter.ToString()); Response.End(); GridSafety.AllowPaging = true; GridSafety.DataBind(); }