Jam*_*213 6 c# crystal-reports
所以我试图将水晶报告导出为pdf,而无需在我的Web应用程序的运行时查看器中使用
ExportToHttpResponse
方法.在加载参数时,一切似乎都正常运行,获取文件名/路径加载报告.但是当我执行部分时,假设创建一个弹出对话框,为用户提供保存,运行,取消选项,任何类型的下载都没有任何反应.不会抛出任何错误.它并没有踩到我所知道的代码的任何部分.它似乎运行ExportToHttpResponse行,然后不执行任何操作.
所以我希望有人可以给我一些方向,我可能会在下面的代码中做错了:
protected void ExportRptButton_Click( object sender, EventArgs e )
{
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.
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");
// 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 ( Exception ex )
{
logger.ErrorFormat("Could not export to pdf! {0}", ex);
}
}
}
Run Code Online (Sandbox Code Playgroud)
一些注意事项:上面显示的LoadParametersFields/LoadStaticTextFields方法似乎工作正常,当用于在crviewer中打开报表时,报表出现并起作用.虽然,如果你希望看到这些方法,我会根据要求抛出它们.
rptParams在开始时是私下宣布的 List<ReportParameter>()
ConfigureCrystalReports方法用于获取和加载报告的文件路径.
非常感谢任何帮助或建议.谢谢.
这个示例代码对我有用;看看错误管理。
protected void btnExport_Click(object sender, EventArgs e)
{
// Stop buffering the response
Response.Buffer = false;
// Clear the response content and headers
Response.ClearContent();
Response.ClearHeaders();
ExportFormatType format = ExportFormatType.PortableDocFormat;
string ext = ".pdf";
string reportName= "myreport";
try
{
reportDocument.ExportToHttpResponse(format, Response, true, reportName);
}
catch (System.Threading.ThreadAbortException)
{
//ThreadException can happen for internale Response implementation
}
catch (Exception ex)
{
//other exeptions will be managed
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13444 次 |
最近记录: |