but i get a message saying "Adobe Reader could not open the file because it is either not a supported file type or the file has been damaged"
Do I need an extract component installed on my machine?
thanks
public static void ExportPDF(string fileName, GridView gv) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName)); HttpContext.Current.Response.ContentType = "application/pdf;"; using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { // Create a form to contain the grid Table table = new Table(); // include the gridline settings table.GridLines = gv.GridLines; // add the header row to the table if (gv.HeaderRow != null) { GridViewExportUtil.PrepareControlForExport(gv.HeaderRow); table.Rows.Add(gv.HeaderRow); } // add each of the data rows to the table foreach (GridViewRow row in gv.Rows) { GridViewExportUtil.PrepareControlForExport(row); table.Rows.Add(row); } // add the footer row to the table if (gv.FooterRow != null) { GridViewExportUtil.PrepareControlForExport(gv.FooterRow); table.Rows.Add(gv.FooterRow); } // render the table into the htmlwriter table.RenderControl(htw); // render the htmlwriter into the response HttpContext.Current.Response.Write(sw.ToString()); HttpContext.Current.Response.End(); } } } #endregion========================================================= protected void Button1_Click(object sender, EventArgs e) { if (this.rdoStudentListExportOptions.SelectedIndex == 1) { // the user wants all rows exported, turn off paging // and rebing the grid before sending it to the export utility this.gvAcademy.AllowPaging = false; this.gvAcademy.DataBind(); } else if (this.rdoStudentListExportOptions.SelectedIndex == 2) { // the user wants just the first 2000, // adjust the PageSize and rebind this.gvAcademy.PageSize = 2000; this.gvAcademy.DataBind(); } // pass the grid that for exporting ... GridViewExportUtil.ExportPDF("HE_STUDENTS.pdf", this.gvAcademy); }
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
http://forums.asp.net/t/1036628.aspx?PageIndex=1