【问题标题】:The source of the report definition has not been specified 3未指定报告定义的来源 3
【发布时间】:2014-05-05 16:19:56
【问题描述】:

我正在使用 Asp.net MVC 4。

我有这个sn-p:

var data = // fill my data.
var rds = new ReportDataSource("MyDataset", data);

var viewer = new ReportViewer();

viewer.LocalReport.Refresh();
viewer.LocalReport.DataSources.Clear();
viewer.LocalReport.DataSources.Add(rds);
viewer.LocalReport.ReportPath = @"Reports/Report1.rdlc";

string mimeType, encoding, extension;
string[] streamids;
Warning[] warnings;

var buffer = viewer.ServerReport.Render("PDF", "C:", out mimeType, out encoding, out extension, out streamids, out warnings);

但是Render方法抛出异常:

Microsoft.Reporting.WebForms.MissingReportSourceException:尚未指定报表定义的来源。

我正在搜索并找到:this 1this 2this 3 等。

我尝试使用这些链接:

尝试1:

viewer.LocalReport.ReportPath = @"../Reports/Report1.rdlc";

尝试2:

viewer.LocalReport.ReportPath = @"../../Reports/Report1.rdlc";

尝试 3:

viewer.LocalReport.ReportPath = @"~/Reports/Report1.rdlc";

尝试 4:

viewer.LocalReport.ReportPath = Server.MapPath(@"~/Reports/Report1.rdlc");

尝试 5:

var fileName = Server.MapPath(@"~/Reports/Report1.rdlc");
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
    viewer.LocalReport.LoadReportDefinition(fs);
}

但是所有这些尝试都会抛出相同的异常。

有人有什么想法吗?我花了几个小时试图让它发挥作用。

【问题讨论】:

    标签: c# asp.net .net asp.net-mvc-4 reportviewer


    【解决方案1】:

    请确保您在使用时已使用以下任一方式

    reportViewer1.LocalReport.ReportPath = @"path/reportName.rdlc"
    

    report 位于 debug 或 release 的 bin 文件夹以外的场景

    或者你可以使用

    reportViewer1.LocalReport.ReportPath = @"reportName.rdlc"
    

    当它在 application.StartupPath 时

    【讨论】:

      【解决方案2】:

      试试这个:

      var data = // fill my data.
      var rds = new ReportDataSource("MyDataset", data);
      
      var viewer = new ReportViewer();
      
      viewer.LocalReport.Refresh();
      viewer.LocalReport.DataSources.Clear();
      viewer.LocalReport.DataSources.Add(rds);
      
      
      
      
                  string fileName=  "Reports/Report1.rdlc";
      
              FileStream S = new FileStream(Server.MapPath(fileName), FileMode.Open);
              viewer.LocalReport.LoadReportDefinition(S);
              S.Close();
      
      string mimeType, encoding, extension;
      string[] streamids;
      Warning[] warnings;
      
      var buffer = viewer.ServerReport.Render("PDF", "C:", out mimeType, out encoding, out extension, out streamids, out warnings);
      

      【讨论】:

      • 感谢您的帮助,但这与问题中使用的 sn-p 相同(尝试 5)。
      • 与您的尝试 5 的唯一区别是我的代码前面没有 ~ 字符。这段代码对我有用。我不知道还有什么问题。
      猜你喜欢
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      • 2013-09-29
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多