Search code examples
c#sql-serverreportviewerrdl

Generating report using C#, ReportViewer and RDL file


I'm trying to generate a report using C# and a RDL file. I have followed examples but I can't get it going. I get the error:

"The path of the item 'sample.rdl' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. (rsInvalidItemPath)". I have tried prepending a slash to the path with no success.

My Reporting Server is in Native mode. My two main questions are:

  1. Do I need parameters?
  2. Where should my RDL file be stored?

Right now I am storing my RDL file within my project. (I don't think this is right)

Here's a code snippet:

const string path = "sample.rdl";
string url = "http://localhost/ReportServer";
string format = "PDF";

var rsReports = new Microsoft.Reporting.WebForms.ReportViewer
{
    ProcessingMode = ProcessingMode.Remote,
    ShowParameterPrompts = false
};
rsReports.ServerReport.ReportServerUrl = new Uri(url);
rsReports.ServerReport.ReportPath = Path.Combine("\\" + Environment.CurrentDirectory, path);
rsReports.ServerReport.Refresh();
byte[] report = rsReports.ServerReport.Render(format.ToUpper());

return report;

Solution

  • Your RDL file must be deployed to the SSRS server. You can do that from within Visual Studio. Right click on your report project and set the report server url to http://localhost/ReportServer.

    Then right click on your report and select deploy. That will deploy your report and data sources to the server.

    You can then try your code again, after you change this line....

    rsReports.ServerReport.ReportPath = "/folder/reportName";
    

    Where folder is the name of the folder on the server where the report was published to, and reportName = "sample" (whithout the .rdl)

    The error your're getting means the path must start with a '/'