2013-01-12 45 views
1

我试图用水晶报表与ASP MVC第一次,但我有一些问题,加载报告:天冬氨酸MVC负荷报告没有

ReportClass rptH = new ReportClass(); 
      rptH.FileName = Server.MapPath("Reports/TestReport.rpt"); 
      rptH.Load(); 

这是rptH.FileName

"rassdk://D:\\ProjectDir\\Pro\\Pro.WebUI\\Reports\\TestReport.rpt" 

值但在Load()我得到异常:

Load report failed.

报告没有任何数据源,它只是空白的报告,一些文字。
也许这很重要。我将项目设置为在本地IIS(不在VS中)上运行。



UPDATE

我已经改变了代码一点点,现在我得到其他一些错误(我也复制在的Inetpub/wwwroot的项目)。这是错误:

Value cannot be null. Parameter name: path2

现在的路径是:

"C:\\inetpub\\wwwroot\\MyProject\\Pro\\Pro.WebUI\\Reports\\TestReport.rpt" 

新的代码是:

ReportClass rptH = new ReportClass(); 
      var path = Server.MapPath("Reports/TestReport.rpt"); 

      rptH.Load(path); 
+0

有人可以至少表明我在哪里可以找问题。我再也没有任何想法了。 – 1110

回答

0

我以前做过与ASP.NET水晶报表。不知道你是否能够做到这一点,但它为我成功地工作。

ReportDocument rptDoc = new ReportDocument(); 
rptDoc.Load(Server.MapPath("TestReport.rpt"); 

Response.Buffer = False 
Response.ClearContent() 
Response.ClearHeaders() 

rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, "TestReport.rpt") 
rptDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "MyReport") 
+0

我应该在inetpub的项目中增加一些安全角色或者类似的东西吗?如果我在浏览器中放置报告网址,请下载我的.rpt文件。所以路径很好。但是应用程序找不到它:( – 1110

+0

你想用它做什么?在浏览器上按需显示? – Matt

+0

我添加了几行文档对象在导出报表时有几个不同的选项。两个和其他选项也许 – Matt

0

如果定义了参数,请检查rpt文件。 如果有,你不需要它们,然后删除它。 如果你需要它们,然后在代码中提供它们的值和描述。 经验:

rep = new ReportDocument(); 
string reportPath = Server.MapPath("Reports/TestReport.rpt"); 
rep.Load(reportPath); 
rep.SetParameterValue(0, "SomeValue"); 
crViewer.ReportSource = rep; 
crViewer.ParameterFieldInfo[0].CurrentValues[0].Description = "ParameterName"; 
crViewer.DataBind(); 
0

试试这个

ReportDocument rd = new ReportDocument(); 
    string FileName = Server.MapPath("~/Report") + "//YourReportName.rpt"; 
    rd.Load(FileName); 
    rd.SetDataSource(dt);