Search results
Suggest a FeaturePDF

This section is specifically for Bold Reports® version less than 3.x. If you are using a higher version of Bold Reports®, recommend you to embed the VB code directly in the report itself, as VBCodeProvider is now available in the .NET Core platform.

How to use the custom code with Report Viewer

Custom code in a report allows to include new custom constants, variables, functions, or subroutines. As the VBCodeProvider is not available in .NET Core platform, report with custom codes requires additional settings to enable this feature. This section describes the steps required to use custom codes with Report Viewer.

Create a custom code class file

  1. Create a new C# class file in your application.
  2. The namespace should be BoldReports.Processing.Helper and class declaration should be public static class Code .
  3. Write the C# methods equivalent to your report VB codes.
  4. Here is the example code to convert the value to USD.
namespace BoldReports.Processing.Helper
{
    public static class Code
    {
        public static string PrintHelloWorld()
        {
            return "Hello World";
        }
    }
}

Create a assembly reference and add it to Report Viewer

If you have created the custom code class, then you need to add the assemblies in the list with what you have used in your application to Report Viewer as shown in following code example.

In our Report Viewer application, assemblies needs to be added before calling the OnReportLoaded method.

  public void OnInitReportOptions(ReportViewerOptions reportOption)
    {
        string basePath = _hostingEnvironment.WebRootPath;
        reportOption.ReportModel.ProcessingMode = ProcessingMode.Local;
        FileStream inputStream = new FileStream(basePath + @"\Resources\Product List.rdlc", FileMode.Open, FileAccess.Read);
        reportOption.ReportModel.Stream = inputStream;
        reportOption.ReportModel.Assemblies.Add(this.GetType().GetTypeInfo().Assembly);
    }