views:

326

answers:

3

I am automatically creating a PDF from some of our reports in a month-end process. I am running into a problem where ReportViewer.LocalReport can't find my report. Within the project, the report files are in "(project root folder)/Reports/report.rdlc". How do I set ReportViewer.LocalReport.ReportPath so I can reference my report file? I would rather not set the full path because I don't know where it would be installed when installed on the client machines.

A: 

The path is always relative to your "current directory" which in most cases is exe file- change rdlc files so that they are copied to the destination folder instead of embedded in resources(usually that's how this is done). The path in your project doesn't matter.

kubal5003
This is intuitive, but in my experience not true. I've tried relative path and it just doesn't find the RDLC file.
sfuqua
A: 

You can store the reports in a "resources" file, and by using an Assembly reader of the given .dll / .exe where the "resource" file is embedded, can read as a streaming reference. Then set your report to the embeded stream to get the report definition.

Special note. If your report has nested sub-reports, the report will fail unless you also set in your LocalReport subreport definition another such reference to your subreport .rdlc file.

DRapp
+4  A: 

Use the Application.StartupPath property, it always points to your EXE.

  using System.IO;
  ...

     string exeFolder = Path.GetDirectoryName(Application.StartupPath);
     string reportPath = Path.Combine(exeFolder, @"Reports\report.rdlc");

You'll want to make sure the report gets copied to your bin\Debug\Reports folder as well so it will work in the IDE.

Hans Passant