5
Answers

exporting datagrid to pdf

Ask a question
faraz akram

faraz akram

13y
4.5k
1

hi am trying to export datagrid to pdf file by using this piece of code:
string
attachment = "attachment; filename=Contacts.pdf";
Response.ClearContent();
Response.AddHeader(
"content-disposition", attachment);
Response.ContentType =
"application/pdf";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
the file save at disk very fine but when i open the file it give me the error as the file cannot be opened either it is damaged or some file sent via email..
plz advise
thanks in advance
 

Answers (5)