【问题标题】:how to deploy WPF application having Crystal Report如何部署具有 Crystal Report 的 WPF 应用程序
【发布时间】:2014-08-28 15:38:50
【问题描述】:

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

我的项目中有 SaleBillReport.rpt 文件。 正在使用报告对象方法加载,其代码如下。

第一个报告显示为 -

案例 1:

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

 _reportViewer.ReportSource = rptObj;

第二份报告显示为 -

案例 2:

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

ReportViewerNew.ReportSource = objReportDoc;

我的问题是,在部署这个项目时,我不需要将任何 .rpt 文件放在任何地方。 它内置在我的应用程序中。

但我必须将我的第二个 .rpt 文件放到任何路径进行显示。(我不想放在任何地方) 那么我如何在部署期间在我的项目中构建案例 2 .rpt 文件。

提前致谢

【问题讨论】:

  • 您使用的是哪种部署方法?设置项目或单击一次或其他什么?
  • 只是在发布模式下构建应用程序。

标签: c# wpf crystal-reports


【解决方案1】:

使用反射找出您的应用程序的安装位置

System.Reflection.Assembly.GetExecutingAssembly

Method explantion

并询问该程序集的文件夹并将您的报告文件名添加到该路径...

【讨论】:

    【解决方案2】:

    一种解决方案可以使用反射,但这有点棘手。

    第二种更简单的方法是使用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 文件。我不想那样做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 2013-11-19
    • 1970-01-01
    相关资源
    最近更新 更多