2013-08-20 104 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; 
相关问题