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.
Use the Application.StartupPath property, it always points to directory where your EXE is located:
using System.IO;
...
string exeFolder = 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. Use xcopy /s /d in a post-build event to get the file(s) copied.