We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use Report Custom codes in SfReportViewer

Platform: UWP |
Control: SfReportViewer

The UWP ReportViewer has some limitations in compiling the VB code functions due to the following reasons:

  1. The reports custom code needs to be compiled against the Microsoft.VisualBasic assemblies and that is not possible in the UWP platform.
  2. The assemblies can be compiled in the server side by using the Microsoft.VisualBasic assemblies and loading it in the UWP; but this also has the similar problem in loading assemblies and does not support the UWP platform.

In order to use the reports Code and to avoid these limitations, the UWP ReportViewer has an alternative solution for the custom Code function support. To use this option, reports custom codes need to be written and compiled in the application.

Steps to run the RDL/RDLC custom code in the UWP ReportViewer:

  1. Create a new blank Universal Windows Application.

New Universal Windows Application

Figure 1: New Universal Windows Application

  1. Add the necessary assemblies to the application.

Adding References

Figure 2: Necessary assemblies added

  1. Create the ReportViewer from XAML. The following code sample shows the same.

XAML

<Page
    x:Class="CustomCode.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CustomCode"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Reports="using:Syncfusion.UI.Xaml.Reports"
    mc:Ignorable="d">
     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Reports:SfReportViewer Name="ReportViewer"/>
    </Grid>
</Page>

 

  1. Load the report stream to the ReportViewer and add the DataSource values as given in the following code.

C#

Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;
                Stream reportStream = assembly.GetManifestResourceStream("CustomCode.Assets.Pivot Table.rdlc");
                this.ReportViewer.ProcessingMode = ProcessingMode.Local;
                this.ReportViewer.LoadReport(reportStream);
                this.ReportViewer.DataSources.Add(new ReportDataSource { Name = "Sales", Value = new AdventureWorks().GetData() });
                this.ReportViewer.RefreshReport();
  1. Add a new class Code.cs to the application and specify the namespace Syncfusion.Reports.Helper (for example, namespace Syncfusion.Reports.Helper).
    Note:

    The namespace of the newly created class must be Syncfusion.Reports.Helper

 

  1. Add a new static class with the name of the Code (for example, public static class Code).
  2. Add the methods with the Static type that is used in your report code functions (for example, GetValueStatus).

C#

namespace Syncfusion.Reports.Helper
{
    public static class Code
    {
        public static string GetValueStatus(string value)
        {
            double dataValue = Convert.ToDouble(value);
             if (dataValue >= 80000)
                return "High Profit";
            else if (dataValue >= 40000)
                return "Moderate Profit";
            else
                return "Average Profit";
        }
    }
}
  1. The executing assembly must be added to the ReportViewer’s Assemblies API in order to process the custom code in the UWP ReportViewer.

C#

this.ReportViewer.Assemblies.Add(this.GetType().GetTypeInfo().Assembly);
  1. You can pass a dataset field, Sales, to this function in an expression.

           =Code.GetValueStatus(Sum(Fields!Sales.Value))

 

  1. Build and Run the application.

 

Sample Link: https://www.syncfusion.com/downloads/support/forum/140225/ze/CustomCode1031223238

 

2X faster development

The ultimate UWP UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile