I'm working with Asp.net MVC 4.
I have this snippet:
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);
But the method Render
throw a exception:
Microsoft.Reporting.WebForms.MissingReportSourceException: The source of the report definition has not been specified.
I'm search and found: this 1, this 2, this 3 and others.
Using these links I tried:
Try 1:
viewer.LocalReport.ReportPath = @"../Reports/Report1.rdlc";
Try 2:
viewer.LocalReport.ReportPath = @"../../Reports/Report1.rdlc";
Try 3:
viewer.LocalReport.ReportPath = @"~/Reports/Report1.rdlc";
Try 4:
viewer.LocalReport.ReportPath = Server.MapPath(@"~/Reports/Report1.rdlc");
Try 5:
var fileName = Server.MapPath(@"~/Reports/Report1.rdlc");
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
viewer.LocalReport.LoadReportDefinition(fs);
}
However all these attempts throw the same exception.
Anyone has some idea? I'm several hours trying to make it work.