2013-08-20 105 views
1

我正在使用visual studio 2010並嘗試加載rpt文件。 我已經使用了下面的代碼。如何在visual studio 2010中使用c#加載rpt文件?

ReportDocument rpt = new ReportDocument(); 
rpt.Load("E:\\Crystal reports docs\\Crystal Reports samples\\Crosstab report"); 

然後我用isLoaded()函數來檢查它是否被加載。

當我編譯程序時,它繼續運行。

任何建議???

在此先感謝!

+0

不能得到喲.... u能更具體? – Dinesh

回答

4

以下是如何加載保存在本地驅動器而不是嵌入式的Crystal報告(.rpt)文件的示例代碼。這樣做的好處是,每次修改報告時都不需要重新編譯程序。另外,.rpt可以從應用程序上傳並存儲在數據庫中,然後寫入文件。使用此方法時不要嵌入.rpt文件。

using System;using CrystalDecisions.CrystalReports.Engine; 
using CrystalDecisions.Shared; 

namespace Report 
{ 
    public partial class Report : Document  
    { 
     public void ReportLoad()  
     { 
      ReportDocument reportDocument = new ReportDocument();  
      string filePath = "C:\Projects\Application\Report\CrystalReport.rpt";     
      reportDocument.Load(filePath); 
      crystalReportViewer.ReportSource = reportDocument; 
     } 
    } 
} 

參見更多

http://scn.sap.com/thread/3312329

How do I load external Crystal Reports (2008) files in c#?

+0

謝謝ramakrishna。我已經完全像你說的那樣做了,但得到了一個名字爲crystalReportViewer的錯誤在上下文中不存在。 – Dinesh

0
ReportDocument reportDocument = new ReportDocument(); 
//ADD 
string filePath = openFileDialog1.FileName; 
reportDocument.Load(filePath); 
crystalReportViewer1.ReportSource = reportDocument; 
相關問題