This section is specifically for Bold Reports® version less than
3.x. If you are using a higher version of Bold Reports®, we recommend that you 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
To use custom code with the Bold Reports® ASP.NET Core Report Viewer, write C# methods equivalent to your report VB code in a Code class and add its assembly to the Report Viewer. Custom code in a report lets you include new custom constants, variables, functions, or subroutines. Because the VBCodeProvider is not available in the .NET Core platform, a report with custom code requires additional settings.
How do I create a custom code class file?
To create a custom code class file for the Report Viewer, add a C# class named Code in the BoldReports.Processing.Helper namespace and write C# methods equivalent to your report VB code.
- Create a new C# class file in your application.
- The namespace should be BoldReports.Processing.Helper and class declaration should be public static class Code .
- Write the C# methods equivalent to your report VB codes.
- Use the following example code as a reference.
namespace BoldReports.Processing.Helper
{
public static class Code
{
public static string PrintHelloWorld()
{
return "Hello World";
}
}
}How do I add the custom code assembly to the Report Viewer?
To add the custom code assembly to the Bold Reports® Report Viewer, add the assemblies that your application uses to the report model assemblies list in the OnInitReportOptions method, as in the following code example:
In the Report Viewer application, add the assemblies before the OnReportLoaded method is called.
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);
}