如何部署具有Crystal Report的WPF应用程序 [英] how to deploy WPF application having Crystal Report

查看:433
本文介绍了如何部署具有Crystal Report的WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我在我的项目中有SaleBillReport.rpt文件。



第一个报表显示为 -



案例1:

  SaleBillReport rptObj = new SaleBillReport文件名
rptObj.SetDataSource(_ReportDataSet);

_reportViewer.ReportSource = rptObj;

第二份报告显示为 -



情况2:

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

ReportViewerNew.ReportSource = objReportDoc;

我的问题是,在部署这个项目时,我不需要把任何。
它在我的应用程序内置。



但我必须把我的第二个.rpt文件到任何路径显示(我不想放在任何地方)
因此,在部署过程中,我在项目中的第二个.rpt文件在构建案例中如何。



提前感谢




一个解决方案可以使用反射,但不是很麻烦。一个会使用 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文件,然后选择始终复制如果较新则复制


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

解决方案

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.

这篇关于如何部署具有Crystal Report的WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆