简体   繁体   English

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

[英]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

Method explantion 方法植入

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.

相关问题 如何在Visual Studio 2010 WPF应用程序中生成水晶报表? - How to Generate crystal report in visual studio 2010 WPF application? 创建设置时如何部署Crystal报表 - how to deploy crystal report while creating setup 如何添加数据库和Crystal Reports Windows窗体应用程序,以便可以将其部署到客户端PC - How to add database and crystal report yo windows form application so it can be deploy to client pc 在生产服务器上部署带有水晶报表的 C# 应用程序 - Deploy C# application with crystal report on production server 如何在MVVM模式WPF应用程序的View模型中的Crystal Report中设置数据源 - How to set Data Source In Crystal Report from View Model in MVVM pattern WPF Application WPF中的现有Crystal报表 - Existing Crystal Report in WPF 我们如何/可以在 C# wnidows 表单应用程序的水晶报告中添加两个没有共同点的表 - how to/can we add two tables having nothing common in between them in crystal report for C# wnidows form application 如何在WPF中显示Crystal Report Viewer的打印对话框 - How to display the print dialog box for crystal report viewer in wpf 如何使用带有sqlite数据库的c# 2015 wpf创建水晶报告? - How to create crystal report with c# 2015 wpf with sqlite database? 如何将WPF应用程序签名和部署为受信任的应用程序 - How to sign and deploy WPF application as a trusted application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM