2015-12-17 46 views
0

我使用以下代码在mvc4中加载报告。但它在导出时出现错误。错误是“系统找不到指定的路径。”MVC中抛出异常的Crystal Reports

请指导我;记住它找不到文件路径

enter image description here

ReportClass rptH = new ReportClass(); 
     rptH.FileName = Server.MapPath("~/CrReports/CrProductsList.rpt"); 
     rptH.Load(); 
     rptH.SetDataSource(new ReportingFactory().AllProductsReport()); 

    Stream stream =rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); 
    return File(stream, "application/pdf"); 

此行抛出错误

Stream stream =rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); 

回答

0

你尝试反斜杠而不是正斜杠(这是我使用的)

rptH.FileName = Server.MapPath("~\CrReport\CrProductsList.rpt"); 

以下是我使用的:

rptH.FileName = @"~\App_Pages\Secure\CrReports\CrProductsList.rpt"; 

在这里看到: https://stackoverflow.com/a/14592492/1438215

编辑:另一个要考虑的,如果报表目录不是解决方案的子目录中,请确保该帐户IIS用来运行应用程序可以读访问CrReport文件夹。

+0

thanx为您的答复。路径非常好。我认为它是报表设计中使用的表名。我创建了一个表格,并在报告中将其命名为表格,然后它的工作状态非常好。 –