We were getting the Thread was being aborted Exception while exporting a report into PDF.
The below code we were using for export a report into PDF.
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
myReportDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, Session["ReportName"].ToString());
Response.Flush();
Response.Close();
Please help me how to resolve this exception.
SAP explains that:
Cause
The issue has been identified and logged under Problem Report ID
ADAPT00765364
. The error is likely caused becauseResponse.End()
is used inside theExportToHttpResponse()
method.It is a known issue that
Reponse.End()
causes the thread to abort. This is by design.See Microsoft KB312629 Article for more info.
Workaround
Resolution
You can write your own code to export a Crystal Report directly to the browser in a format such as PDF, Word, Excel, etc. You must make sure you use the appropriate content type.
Sample code to export Crystal Report to web browser as PDF
The error is thrown because a call to response.End() is made inside of ExportToHttpResponse. Remove your calls to Flush and Close the response and wrap your call to ExportToHttpResponse inside a try/catch block to catch and ignore the System.Threading.ThreadAbortException.