New to Telerik Reporting? Download free 30-day trial

Remove unsupported tags from HtmlTextBox value

Environment

Product Progress® Telerik® Reporting

Description

HtmlTextBox does not support all the Html tags, and an error is thrown when an unsupported tag is met, as the Reporting Engine cannot process it. Sometimes it is necessary to render the tags that can be recognized by the HtmlTextBox and just ignore the rest of the markup. Here is how to achieve this.

Solution

Create a custom User Function that manipulates the markup and converts it to a text that can be parsed by the HtmlTextBox. The HtmlFormatProvider from Telerik UI for WinForms can be used to perform the actual conversion. Here is a sample code for the user function:

using Telerik.WinForms.Documents.FormatProviders.Html;

namespace HtmlParser
{
    public static class ParseHtml
    {
        public static string HtmlAdapt(string markup)
        {
            HtmlExportSettings exportSettings = new HtmlExportSettings();
            exportSettings.ImageExportMode = ImageExportMode.None;
            exportSettings.StylesExportMode = StylesExportMode.Inline;
            exportSettings.DocumentExportLevel = DocumentExportLevel.Fragment;
            exportSettings.StyleRepositoryExportMode = StyleRepositoryExportMode.DontExportStyles;

            HtmlFormatProvider provider = new HtmlFormatProvider();
            provider.ExportSettings = exportSettings;
            string outputHtml = provider.Export(provider.Import(markup));

            return outputHtml;
        }
    }
}

It is essential to use the HtmlExportSettings from the above code to receive an output that can be parsed by the HtmlTextBox.

The above user function should take as an argument the markup to be manipulated, and the returned value should be used as a Value for the HtmlTextBox :

= HtmlParser.ParseHtml.HtmlAdapt(Fields.MarkUp)

Fields.MarkUp should contain the markup to be converted to a value that HtmlTextBox can parse.

Notes

The User Function should be declared either in the current report's assembly or in AssemblyReferences element nodes in Telerik.Reporting section of the application configuration file.

For Standalone designer the configuration file is Telerik.ReportDesigner.exe.config and is typically in (Telerik Reporting installation folder)\Report Designer (for example C:\Program Files (x86)\Progress\Telerik Reporting R2 2018\Report Designer). Check also Extending Report Designer article. The user function assembly and all its dependencies (see below) should be copied to the Standalone designer folder.

Required assemblies not included in Telerik Reporting :

(from UI.for.WinForms.Common NuGet package)

  • TelerikCommon.dll
  • Telerik.WinControls.dll
  • Telerik.WinControls.UI.dll

(from UI.for.WinForms.RichTextEditor NuGet package)

  • Telerik.WinControls.RichTextEditor.dll
In this article