Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i'm converting gridviewdata to pdf i'm getting the below error,
''the file is damaged and couldnot be open ''

how to fix this error using asp.net3.5
Posted
Comments
Shambhoo kumar 25-Sep-12 3:14am    
w
fjdiewornncalwe 27-Sep-12 10:54am    
You'll have to give us a little more information than that. At first glance it looks like the pdf you generated is not valid. We'd have to see how you build your pdf in order to give you any real advice.

C#
protected void Button4_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition","attachment;filename=GridViewExport.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.AllowPaging = false;
    GridView1.DataBind();
    GridView1.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);//this is the error line
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();  
}

Regard
Sham
:)

i think this is helpfull to u....
 
Share this answer
 
v2
Comments
Bobby Teja 30-Nov-12 7:13am    
i am facing an as below

Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
arunava patra 23-Oct-13 1:31am    
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the specified ASP.NET
// server control at run time.

}
Bobby Teja 30-Nov-12 7:14am    
Can any one help me out
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900