繁体   English   中英

如何部署具有Crystal Report的WPF应用程序

[英]how to deploy WPF application having Crystal Report

我的项目中有两个水晶报表。

我的项目中有SaleBillReport.rpt文件。 使用报告对象方法加载的代码如下所示。

第一份报告显示为-

情况1:

 SaleBillReport rptObj = new SaleBillReport();//My Rpt file name
 rptObj.SetDataSource(_ReportDataSet);

 _reportViewer.ReportSource = rptObj;

第二份报告显示为-

情况2:

ReportDocument objReportDoc = new ReportDocument();
objReportDoc.Load(@"D:\\" + "MyReport.rpt");

ReportViewerNew.ReportSource = objReportDoc;

我的问题是,在部署此项目时,我不需要在任何地方放置任何.rpt文件。 它是在“我的应用程序”中内置的。

但是我必须将我的第二个.rpt文件放到任何显示路径上。(我不想放在任何地方)所以我在部署期间如何在我的项目中构建案例2 .rpt文件。

提前致谢

使用Reflection找出应用程序的安装位置

System.Reflection.Assembly.GetExecutingAssembly

方法植入

并询问该程序集的文件夹,并将您的报告文件名添加到该路径...

一种解决方案是使用反射,但这并不棘手。

第二个也是最简单的一个是使用Environment.CurrentDirectory

为此,请修改您的Case 2代码,如下所示:

ReportDocument objReportDoc = new ReportDocument();
string reportPath = System.IO.Path.Combine(Environment.CurrentDirectory, "MyReport.rpt");
objReportDoc.Load(reportPath);

ReportViewerNew.ReportSource = objReportDoc;

并且要使您的报告在当前目录位置始终永久保存,只需转到MyReport.rpt文件的属性,然后选择“始终复制”“如果更新则复制”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM