Telerik Reporting

User functions allow you to extend the default behavior of the Telerik Reporting engine. User functions are public static (Public Shared in VB.NET) methods that should always return a value and can take an arbitrary number of input parameters. See the code example below:

CopyC#
public class Report1 : Telerik.Reporting.Report
{
    //...
    public static Image ResolveUrl(string relativeUrl)
    {
        string path = HttpContext.Current.Server.MapPath(relativeUrl);
        return Image.FromFile(path);
    }
    //...
}
CopyVB.NET
Public Class Report1 Inherits Telerik.Reporting.Report
    '...
    Public Shared Function ResolveUrl(ByVal relativeUrl As String) As Image
        Dim path As String = HttpContext.Current.Server.MapPath(relativeUrl)
        Return Image.FromFile(path)
    End Function
    '...
End Class

According to their scope, there are two different types of user functions:

  1. Report scoped user functions: such functions are any public static (Public Shared in VB.NET) methods of the current report class. The report scoped user functions can be invoked from an expression by their name, specifying the necessary parameters in the braces:

    Invoking a Report Scoped User Function

    = ResolveUrl("~/Images/Logo.jpg")

  2. Assembly scoped user functions: such functions are any public static (Public Shared in VB.NET) methods that reside in the same assembly as the current report class. The report scoped user functions can be invoked from an expression by their fully qualified name, including the full namespace and the name of the type they belong to, and specifying the necessary parameters in the braces:

    Invoking an Assembly Scoped User Function

    = Telerik.Reporting.Report.Report1.ResolveUrl("~/Images/Logo.jpg")

If the current assembly contains many public static (Public Shared in VB.NET) methods, this might produce some clutter in the Edit Expression dialog, when browsing for existing user functions. In order to overcome this problem, you can use the Browsable attribute to hide any methods, which are not intended to be used as user functions. See the code example below:

CopyC#
public class Report1 : Telerik.Reporting.Report
{
    //...
    [Browsable(false)]
    public static Image ResolveUrl(stringrelativeUrl)
    {
        string path = HttpContext.Current.Server.MapPath(relativeUrl);
        return Image.FromFile(path);
    }
    //...
}
CopyVB.NET
Public Class Report1 InheritsTelerik.Reporting.Report
    '...
    <Browsable(False)>;
    Public Shared FunctionResolveUrl(ByValrelativeUrl AsString) AsImage
        Dim path As String= HttpContext.Current.Server.MapPath(relativeUrl)
        Return Image.FromFile(path)
    End Function
    '...
End Class