Click here to Skip to main content
12,635,398 members (24,510 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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 24-Sep-12 22:09pm
Comments
shambhoo kumar 25-Sep-12 3:14am
   
w
Marcus Kramer 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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....
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100