How to convert gridview values to PDF in C#? I am getting error when i write the below code. Can you pls tell me how to do?adobe reader could not open 'test[1].pdf' because it is either not supported file type or because the file has been damaged LoadGrid();
GridView oGridView = new GridView();
oGridView.DataSource = dsResult.Tables[0];
oGridView.DataBind();
string attachment = "attachment; filename=Abend.pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());
Response.Charset = "";
this.EnableViewState = false;
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("\r\n");
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
oGridView.RenderControl(hw);
Response.AppendHeader("content-disposition", "attachment;filename=" + attachment);
Response.Write(tw.ToString());
Response.End();