Mike Wills Mike Wills - 1 year ago 220
C# Question

Getting the relative path to the rdlc report in my winform app

I am automatically creating a PDF from some of our reports in a month-end process. I am running into a problem where

can't find my report. Within the project, the report files are in "(project root folder)/Reports/report.rdlc".

How do I set
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download