![](/img/trans.png)
[英]How to Generate crystal report in visual studio 2010 WPF application?
[英]how to deploy WPF application having Crystal Report
我的項目中有兩個水晶報表。
我的項目中有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文件。
提前致謝
使用Reflection找出應用程序的安裝位置
System.Reflection.Assembly.GetExecutingAssembly
並詢問該程序集的文件夾,並將您的報告文件名添加到該路徑...
一種解決方案是使用反射,但這並不棘手。
第二個也是最簡單的一個是使用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文件的屬性,然后選擇“始終復制”或“如果更新則復制” 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.