Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 737
Mike Wills Avatar asked Apr 23 '10 21:04

Mike Wills


People also ask

How to create RDLC report in Windows Forms (WinForms)?

The RDLC Report in in Windows Forms (WinForms) application will be populated using Typed DataSet. In this article I will explain a simple tutorial with an example and sample code to create RDLC Report in Windows Forms (WinForms) application using C# and VB.Net.

How to create a dynamic RDLC report in access 2013?

Step 1: Create a new project name as “ Dynamic RDLC Report ” and press button “ OK ”. Step 2: Drag and drop the one textbox, button and report viewer, and label from toolbox and set the label name “ Employee ID ”. And add the Oledb connection. Step 3: After that we can create a database in Microsoft Access 2013.

How do I view reports in a WinForms application?

Using the WinForms ReportViewer Control. To view reports that have been deployed to a report server or reports that exist on the local file system, you can use the WinForms ReportViewer control to render them in a Windows application.

How to view the RDLC report?

You will need to click on the small arrow present on the top right corner of the Report Viewer and choose the RDLC Report as shown below. 10. Populating the RDLC Report from Database


1 Answers

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.

like image 143
Hans Passant Avatar answered Oct 21 '22 09:10

Hans Passant