【发布时间】: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 1、this 2、this 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