2014-04-27 279 views
0

我希望我的水晶報告,如果項目移動到另一個文件夾,保持工作而不更改代碼。現在多數民衆贊成在我的WinForm路徑水晶報告c#

ReportDocument cryRpt = new ReportDocument(); 
     string reportPath = Path.Combine(Environment.CurrentDirectory, "CrystalReport1.rpt"); 
     cryRpt.Load(reportPath); 
     crystalReportViewer1.ReportSource = cryRpt; 
     crystalReportViewer1.Refresh(); 

Error

這意味着代碼:不支持的操作。無法打開由JRC引擎堆棧編寫的文檔C++

+0

該代碼心不是工作,我得到的報告心不是加載錯誤。 – Kiirito

回答

0

您確定rpt文件存在嗎?

看起來像錯誤是指其他問題,而不是文件位置。

試試這個,爲了測試是否文件位置的問題或不:

ReportDocument cryRpt = new ReportDocument(); 

     string rpt = "CrystalReport1.rpt"; 
     string reportFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); 

     string reportPath = Path.Combine(reportFolder, rpt); 

     if(!File.Exists(reportPath)) 
     { 
      MessageBox.Show("File " + rpt + " not found in " + reportFolder); 
      return; 
     } 
     cryRpt.Load(reportPath); 
     crystalReportViewer1.ReportSource = cryRpt; 
     crystalReportViewer1.Refresh(); 
+0

我得到一個MessageBox代碼錯誤..它說,它的類型,但它用作變量 – Kiirito

+0

@Kiirito你可能可以弄清楚爲什麼..將其更改爲'MessageBox.Show()'。 –

+0

好吧,它說文件沒有找到,仍然該文件在項目文件夾 – Kiirito