1

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.

Community
  • 1
  • 1
Jonny Piazzi
  • 3,684
  • 4
  • 34
  • 81

2 Answers2

2

Please make sure that you have either used one of the following when using

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

scenario when report is located other than bin folder of debug or release

or you can use

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

when its at application.StartupPath

Bhushan Pawar
  • 451
  • 4
  • 13
0

Try this:

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);
Bura Chuhadar
  • 3,653
  • 1
  • 14
  • 17