Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string attachment = "attachment; filename=FormA5.pdf";
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("content-disposition", attachment);
        HttpContext.Current.Response.ContentType = "application/pdf";
        StringWriter stw = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);
        Document doc = new Document(iTextSharp.text.PageSize.A4, 30, 30, 50, 50);
        //string path = Server.MapPath("PDFs");
        PdfWriter.GetInstance(doc, HttpContext.Current.Response.OutputStream);
        DataTable dt = emp.SelectEmployeeWithDesgnDeptLocComp(empid);
        doc.Open();
        Paragraph paragraphheader = new Paragraph();
        paragraphheader.SpacingAfter = 1f;
        float[] headercols = { 1f, 2f, 1.2f, 2f };
        PdfPTable table = new PdfPTable(headercols);
        table.WidthPercentage = 100f;
        PdfPCell cell = GetFormName(company);





  StringReader str = new StringReader(stw.ToString());
        HTMLWorker htmlworker = new HTMLWorker(doc);
        htmlworker.Parse(str);
        doc.Close();
        HttpContext.Current.Response.Write(doc);
        HttpContext.Current.Response.End();

//Data = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
Posted
Comments
Sandeep Mewara 14-May-12 3:02am    
Error at what line? What are you trying to do? If you need help, you have to be clear and share details.
piushshukla 14-May-12 3:07am    
HttpContext.Current.Response.End(); this line shows an error

1 solution

Ok.

In place of Response.End you have to use HttpContext.Current.ApplicationInstance.CompleteRequest method to bypass the code execution to the Application_EndRequest event.

Look here for details: Microsoft Support: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer[^]
 
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