问题描述
我们在将报告导出为 PDF 时遇到线程被中止异常.
We were getting the Thread was being aborted Exception while exporting a report into PDF.
我们用于将报告导出为 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();
请帮我解决这个异常.
推荐答案
SAP 解释说:
该问题已被识别并记录在问题报告 ID ADAPT00765364
下.该错误可能是因为 Response.End()
在 ExportToHttpResponse()
方法中使用.Reponse.End()
导致线程中止是一个已知问题.这是设计使然.
有关详细信息,请参阅 Microsoft KB312629 文章.
The issue has been identified and logged under Problem Report ID ADAPT00765364
.The error is likely caused because Response.End()
is used inside the ExportToHttpResponse()
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.
....
try
{
reportDocument.ExportToHttpResponse(format, Response, true, Page.Title);
}
catch (System.Threading.ThreadAbortException)
{
}
....
分辨率
您可以编写自己的代码,以 PDF、Word、Excel 等格式将 Crystal Report 直接导出到浏览器.您必须确保使用适当的内容类型.
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.
将 Crystal Report 以 PDF 格式导出到 Web 浏览器的示例代码
Sample code to export Crystal Report to web browser as PDF
try
{
boReportDocument.Load(Server.MapPath(@"MyReport.rpt"));
System.IO.Stream oStream = null;
byte[] byteArray = null;
oStream = boReportDocument.ExportToStream (ExportFormatType.PortableDocFormat);
byteArray = new byte[oStream.Length];
oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.BinaryWrite(byteArray);
Response.Flush();
Response.Close();
boReportDocument.Close();
boReportDocument.Dispose();
}
catch (Exception ex)
{
string s = ex.Message;
}
这篇关于水晶报告中的线程被中止异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!