【发布时间】:2017-01-12 07:15:11
【问题描述】:
我想直接将水晶报告下载到 pdf 中一起查看 CommonReportViewer.aspx 页面,我正在本地服务器上运行我的项目,源 MYPROJECT 和 (.rpt) 报告在 D:\MYPROJECT\Reporting\Deposit\报告。我在 Stackoverflow 上尝试了不同的解决方案,即 ExportToDisk,ExportOptions 等等,但无法获得解决方案。在我查看银行报告的情况下,我通过表单提供了报告参数,最后达到报告参数并显示报告。我的问题是如何直接以 pdf 格式下载该报告,因为我需要打印多页报告。
CommonReportViewer.aspx.cs:
public partial class CommonReportViewer : System.Web.UI.Page
{
ReportDocument mainDoc = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
try
{
CrystalReport report = new CrystalReport();
report = (CrystalReport)Session["NLK_REPORT"];
DateTime t1 = DateTime.Now;
mainDoc.Load(report.ReportFilePath, OpenReportMethod.OpenReportByDefault);
mainDoc.RecordSelectionFormula = report.SelectionCriteria;
mainDoc.Refresh();
string server = "NLKNEWDB";
string userID = report.UserID;
string password = report.Password;
this.ApplyLogonInfo(mainDoc, server, userID, password);
foreach (ReportParameter param in report.ParamList)
{
mainDoc.SetParameterValue(param.ParamName, param.ParamValue);
}
foreach (SubReport sr in report.SubReportList)
{
this.ApplyLogonInfo(mainDoc, server, userID, password);
foreach (ReportParameter param in sr.ParamList)
{
mainDoc.SetParameterValue(param.ParamName, param.ParamValue, sr.SubReportName);
}
}
mainDoc.SetDatabaseLogon(userID, password, server, "");
this.crptViewer.ReportSource = mainDoc;
mainDoc.DataSourceConnections.Clear();
}
finally
{
}
}
void ApplyLogonInfo(ReportDocument report, string server, string userID, string password)
{
TableLogOnInfo info = new TableLogOnInfo();
ConnectionInfo cinfo = new ConnectionInfo();
cinfo.ServerName = server;
cinfo.UserID = userID;
cinfo.Password = password;
info.ConnectionInfo = cinfo;
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in report.Database.Tables)
{
tbl.ApplyLogOnInfo(info);
}
}
private void Page_Unload(object sender, System.EventArgs e)
{
if (mainDoc != null)
{
mainDoc.Close();
mainDoc.Dispose();
}
}
}
【问题讨论】:
标签: c# asp.net pdf crystal-reports crystal-reports-2010