Skip to content

1004 Winform Viewer

Peter Gill edited this page May 3, 2024 · 3 revisions
dotnet add package Majorsilence.Reporting.RdlViewer

First add DataProviders.dll, RdlCri.dll, RdlEngine.dll, and RdlViewer.dll as references to your project. Next make sure RdlEngineConfig.xml is part of your project. Set build action to "None" and Copy to output directory to "Copy if newer". Make sure that in RdlEngineConfig.xml that the dataprovider you are using has the correct CodeModule path.

If you are using something other then microsoft sql as a database you may need to enter a path to the assemblies. For example if you are using sqlite make sure that the path to the System.Data.Sqlite.dll is set. If System.Data.Sqlite.dll is going to be in the same directory as your application you are fine.

Embed Report Viewer

This is the most simple example of using the RdlViewer control. It loads a report with no parameters. It creates an instance of RdlViewer, set the SourceFile location.

using System.Windows.Forms;
using fyiReporting;
using fyiReporting.RDL;
using fyiReporting.RdlViewer;

class Program
{
	[STAThread]
	static void Main()
	{
		System.Windows.Forms.Form frm = new System.Windows.Forms.Form();
		frm.Height = 600;
		frm.Width = 800;

		fyiReporting.RdlViewer.RdlViewer rdlView = new fyiReporting.RdlViewer.RdlViewer();
		rdlView.SourceFile = new Uri(@"\path\to\your\report.rdl");
                rdlView.Rebuild();

		rdlView.Dock = DockStyle.Fill;
		frm.Controls.Add(rdlView);

		Application.Run(frm);
	}
}

Embed Report Viewer, Report has Parameters

This example loads a report with parameters. It creates an instance of RdlViewer, sets the SourceFile location and finally sets the report parameters.

using System.Windows.Forms;
using fyiReporting;
using fyiReporting.RDL;
using fyiReporting.RdlViewer;

class Program
{
	[STAThread]
	static void Main()
	{
		System.Windows.Forms.Form frm = new System.Windows.Forms.Form();
		frm.Height = 600;
		frm.Width = 800;

		fyiReporting.RdlViewer.RdlViewer rdlView = new fyiReporting.RdlViewer.RdlViewer();
		rdlView.SourceFile = new Uri(@"\path\to\your\report_with_parameters.rdl");
		rdlView.Parameters += string.Format("&TestParam1={0}&TestParam2={1}", "Value 1", "Value 2");
		rdlView.Rebuild();

		rdlView.Dock = DockStyle.Fill;
		frm.Controls.Add(rdlView);

		Application.Run(frm);
	}
}