[英]how to deploy WPF application having Crystal Report
I have two crystal reports in my Project. 我的项目中有两个水晶报表。
I am having SaleBillReport.rpt file in My project. 我的项目中有SaleBillReport.rpt文件。 which is being loaded using report object method whose code is given below. 使用报告对象方法加载的代码如下所示。
First report is shown as - 第一份报告显示为-
Case 1: 情况1:
SaleBillReport rptObj = new SaleBillReport();//My Rpt file name
rptObj.SetDataSource(_ReportDataSet);
_reportViewer.ReportSource = rptObj;
Second report is shown as - 第二份报告显示为-
Case 2: 情况2:
ReportDocument objReportDoc = new ReportDocument();
objReportDoc.Load(@"D:\\" + "MyReport.rpt");
ReportViewerNew.ReportSource = objReportDoc;
My problem is that while deploying this project i don't need to Put any .rpt file anywhere. 我的问题是,在部署此项目时,我不需要在任何地方放置任何.rpt文件。 It is in-built in My application. 它是在“我的应用程序”中内置的。
But i have to put my 2nd .rpt file to any path for display.(i don't want to put anywhere) So how i in build case 2 .rpt file in my project during Deployment. 但是我必须将我的第二个.rpt文件放到任何显示路径上。(我不想放在任何地方)所以我在部署期间如何在我的项目中构建案例2 .rpt文件。
Thanks in advance 提前致谢
Use Reflection to find out where your application is installed 使用Reflection找出应用程序的安装位置
System.Reflection.Assembly.GetExecutingAssembly System.Reflection.Assembly.GetExecutingAssembly
and ask the folder of that assembly and add your report filename to that path... 并询问该程序集的文件夹,并将您的报告文件名添加到该路径...
One solution can be using reflection, but it is little tricky. 一种解决方案是使用反射,但这并不棘手。
Second one and the simpler one would be using Environment.CurrentDirectory
. 第二个也是最简单的一个是使用Environment.CurrentDirectory
。
For that, modify your Case 2 code like this - 为此,请修改您的Case 2代码,如下所示:
ReportDocument objReportDoc = new ReportDocument();
string reportPath = System.IO.Path.Combine(Environment.CurrentDirectory, "MyReport.rpt");
objReportDoc.Load(reportPath);
ReportViewerNew.ReportSource = objReportDoc;
and for your report to be always permanent at the current directory location, just go to the properties of your MyReport.rpt file and select Copy Always or Copy if newer . 并且要使您的报告在当前目录位置始终永久保存,只需转到MyReport.rpt文件的属性,然后选择“始终复制”或“如果更新则复制” 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.