Skip to content

Hyperlink Custom Action

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

See Sample Hyperlink Custom Action example

Works in the .NET viewer control.

You can pass information from your report, if viewed in the .net control, back to your application. To do this select a field and change the action to hyperlink.

Select Field

Select report field

Once you have selected the field click action button and select hyperlink.

Add hyperlink action

Write your hyperlink expression.

Write hyperlink expression

If you write your expression in a uri format you can use the .net Uri class to easily read the data.

Code that handles the above screenshot hyper links.

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();

        // Subscribe to Hyperlink event
        rdlView.Hyperlink += rdlViewer1_Hyperlink;

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

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

        Application.Run(frm);
    }

    private static void reportViewer_Hyperlink(object sender, fyiReporting.RdlViewer.HyperlinkEventArgs e)
    {
        Uri uri = new Uri(e.Hyperlink);

        // Look for "lastname:" set in hyperlink expression.
        if (uri.Scheme.ToLower() == "lastname")
        {
            // It is very important to set Cancel to true.  If not it will attempt
            // to launch the hyperlink
            e.Cancel = true;

            // do whatever you want with uri
        }
    }

}