我正在使用Asp.net MVC 4。
我有这个片段:
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);
}
然而,所有这些尝试都会引发相同的异常。
任何人都有一些想法?我有几个小时试图让它发挥作用。
答案 0 :(得分:2)
请确保您在使用
时使用过以下任一项reportViewer1.LocalReport.ReportPath = @"path/reportName.rdlc"
报告位于调试或发布的bin文件夹以外的场景
或者您可以使用
reportViewer1.LocalReport.ReportPath = @"reportName.rdlc"
当它在application.StartupPath
时答案 1 :(得分:0)
试试这个:
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);