Rajveer singh

Rajveer singh

  • 800
  • 1k
  • 251k

Thread was being aborted exception

Dec 27 2015 11:58 PM
Hi all
i Genarate a pdf file from gridview data using iTextSharp dll , but click buttion show the error and
 
attach file for ITextEvent
 
========Error==============
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at admin_File_upload_report.LinkButton2_Click(Object sender, EventArgs e) in d:\MIB.NIC.IN\mib\admin\File_upload_report.aspx.cs:line 851
=============My cs code===============
Document pdfDoc = new Document(PageSize.A3, 10f, 10f, 100f, 10f);
try
{
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfWriter.PageEvent = new ITextEvents();
//open the stream
pdfDoc.Open();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + ddlcategory.SelectedItem.Text + "_" + ddlsubcategory.SelectedItem.Text + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
GridView1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(GridView1);
frm.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
pdfDoc.Open();
pdfDoc.Add(new Paragraph("Category(Level1):-" + ddlcategory.SelectedItem.Text));
pdfDoc.Add(new Paragraph("Subcategory(Level2):-" + ddlsubcategory.SelectedItem.Text));
//pdfDoc.Add(new Paragraph("Document Status:-" + lbl3.SelectedItem.Text + " Documents"));
htmlparser.Parse(sr);
Response.Write(pdfDoc);
pdfDoc.Close();
Response.End();
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
finally
{
}

Answers (5)