Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are several steps involved in local reporting using RDL on .NET 4.0 at the client-side:

  1. Install the Microsoft Report Viewer runtime on the client machine.

  2. Create a new instance of the ReportViewer control in the client-side application.

  3. Set the ReportViewer's processing mode to "Local".

  4. Load the RDL file into the ReportViewer control.

  5. Set any relevant report parameters, such as date ranges or filter criteria.

  6. Render the report in the ReportViewer control.

  7. Save the report output to a desired format, such as PDF, Excel, or Word.

Here is some sample code to help you get started:

using Microsoft.Reporting.WinForms;
using System;
using System.IO;
using System.Windows.Forms;

namespace SampleApplication
{
    public partial class MainForm : Form
    {
        private string reportPath = "C:\\Reports\\MyReport.rdl";

        public MainForm()
        {
            InitializeComponent();
        }

        private void RenderReport()
        {
            LocalReport localReport = new LocalReport();
            localReport.ReportPath = reportPath;

            // Set report parameters
            ReportParameter startDate = new ReportParameter("StartDate", "2022-01-01");
            ReportParameter endDate = new ReportParameter("EndDate", "2022-01-31");
            localReport.SetParameters(new ReportParameter[] { startDate, endDate });

            // Render the report
            byte[] reportBytes = localReport.Render("PDF");

            // Save the report to disk
            File.WriteAllBytes("C:\\Reports\\MyReport.pdf", reportBytes);
        }
    }
}

Note that this is just a basic example, and there may be additional steps required depending on your specific reporting needs. It is also important to verify that your RDL file is compatible with the ReportViewer control and that all necessary data sources are available on the client machine.