C# 如何使用Crystal Report部署WPF应用程序
我有两个水晶报告在我的项目 我的项目中有SaleBillReport.rpt文件。 正在使用下面给出代码的报表对象方法加载 第一份报告如下: 案例1:C# 如何使用Crystal Report部署WPF应用程序,c#,wpf,crystal-reports,C#,Wpf,Crystal Reports,我有两个水晶报告在我的项目 我的项目中有SaleBillReport.rpt文件。 正在使用下面给出代码的报表对象方法加载 第一份报告如下: 案例1: SaleBillReport rptObj = new SaleBillReport();//My Rpt file name rptObj.SetDataSource(_ReportDataSet); _reportViewer.ReportSource = rptObj; ReportDocument objReportDoc =
SaleBillReport rptObj = new SaleBillReport();//My Rpt file name
rptObj.SetDataSource(_ReportDataSet);
_reportViewer.ReportSource = rptObj;
ReportDocument objReportDoc = new ReportDocument();
objReportDoc.Load(@"D:\\" + "MyReport.rpt");
ReportViewerNew.ReportSource = objReportDoc;
第二份报告如下:
案例2:
SaleBillReport rptObj = new SaleBillReport();//My Rpt file name
rptObj.SetDataSource(_ReportDataSet);
_reportViewer.ReportSource = rptObj;
ReportDocument objReportDoc = new ReportDocument();
objReportDoc.Load(@"D:\\" + "MyReport.rpt");
ReportViewerNew.ReportSource = objReportDoc;
我的问题是,在部署这个项目时,我不需要将任何.rpt文件放在任何地方。
它内置于我的应用程序中
但是我必须把我的第二个.rpt文件放在任何路径上显示。(我不想放在任何地方)
因此,我如何在部署期间在项目中构建case2.rpt文件
提前感谢使用反射查找应用程序的安装位置 System.Reflection.Assembly.GetExecutionGassembly
然后询问该程序集的文件夹并将您的报告文件名添加到该路径…一种解决方案可以使用反射,但这有点棘手 第二个和更简单的方法是使用
Environment.CurrentDirectory
为此,修改案例2代码如下-
ReportDocument objReportDoc = new ReportDocument();
string reportPath = System.IO.Path.Combine(Environment.CurrentDirectory, "MyReport.rpt");
objReportDoc.Load(reportPath);
ReportViewerNew.ReportSource = objReportDoc;
要使您的报告始终永久保存在当前目录位置,只需转到MyReport.rpt文件的属性,然后选择始终复制或复制(如果更新),您使用的是哪种部署方法?安装项目或单击一次或其他什么?只是在发布模式下构建应用程序。如果我选择“始终复制”,它将在.exe文件夹中创建.rpt文件。我不想那样做。