how to deploy WPF application having Crystal Repor

2019-09-19 07:29发布

I have two crystal reports in my Project.

I am having SaleBillReport.rpt file in My project. which is being loaded using report object method whose code is given below.

First report is shown as -

Case 1:

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

 _reportViewer.ReportSource = rptObj;

Second report is shown as -

Case 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. 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.

Thanks in advance

2条回答
乱世女痞
2楼-- · 2019-09-19 07:52

One solution can be using reflection, but it is little tricky.

Second one and the simpler one would be using Environment.CurrentDirectory.

For that, modify your Case 2 code like this -

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.

查看更多
淡お忘
3楼-- · 2019-09-19 08:17

Use Reflection to find out where your application is installed

System.Reflection.Assembly.GetExecutingAssembly

Method explantion

and ask the folder of that assembly and add your report filename to that path...

查看更多
登录 后发表回答