C# 尝试导出为pdf时出现分析器错误异常
所以我真的可以用一个线索来解释为什么会发生这种情况,以及如何解决它。我正在尝试使用以下代码将crystal报表导出为pdf:C# 尝试导出为pdf时出现分析器错误异常,c#,asp.net,crystal-reports,C#,Asp.net,Crystal Reports,所以我真的可以用一个线索来解释为什么会发生这种情况,以及如何解决它。我正在尝试使用以下代码将crystal报表导出为pdf: protected void ExportRptButton_Click( object sender, EventArgs e ) { Datamart.UI.Reporting.Web.ReportParamsSvc.ReportDefinition rptCfg = SelectedReport; if
protected void ExportRptButton_Click( object sender, EventArgs e )
{
Datamart.UI.Reporting.Web.ReportParamsSvc.ReportDefinition rptCfg = SelectedReport;
if ( null != SelectedReport )
{
rptParams.Clear();
rptParams = null;
// Get the report document
// string filePath = Server.MapPath( @"~\Reports\" + SelectedReport.FileName + ".rpt" );
// Declare a new Crystal Report Document object and load the report file into the report document.
ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
ConfigureCrystalReports(rptDoc);
// repDoc.Load(rptFileName);
// AddParameters();
// Set the report parameters the report object.
//LoadReportParameterValues(SelectedReport);
LoadParameterFields(rptDoc);
// Set the static text fields in the report object.
LoadStaticTextFields(rptDoc);
try
{
if (rptDoc.IsLoaded)
{
// Stop buffering the response
Response.Buffer = false;
// Clear the response content and headers
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
// Export the Report to Response stream in PDF format and file name Customers
rptDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "DirectAccessReport");
// Response.Filter.Flush();
// Response.Flush();
// rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, "~/PDF_Folder");
// There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
}
}
catch (System.Threading.ThreadAbortException ex)
{
logger.ErrorFormat("Could not export to pdf: threading! {0}", ex);
}
catch ( Exception ex )
{
logger.ErrorFormat("Could not export to pdf! {0}", ex);
}
}
}
“ConfigureCrystalReports”只获取报告的文件路径
“LoadParameterFields”填充报告的参数,我确信它可以工作,因为它的代码与我在CRViewer中打开报告时填充参数的代码相同。但是,如果你想看看它的作用,那么让我知道,我会添加它
“LoadStaticTextFields”也可以这样说,它只获取报表中标签的文本值
我收到的错误可以在下面的img中找到:
关于问题发生在哪里,我的最佳猜测是在try循环中。正如您所看到的,我尝试了几种不同的方法来处理大多数注释掉的代码中的响应字段
我花了大量时间寻找答案,大多数人说我必须从代码中删除所有Response.Write()调用,但是我没有在代码中的任何地方使用Response.Write()
非常感谢您的帮助或建议。谢谢。尽量不要清除标题。我尝试了你的建议,但仍然抛出一个解析器错误。