Linq Reporting - How to import and convert html field?

When working with mail merge I use this approach to convert html markup:

I handle the FieldMergingCallback and if a field name contains “html” then I threat it as such and perform the conversion (see code snippets below).

My question is: How can I do something similar with the Linq Reporting Engine?

Snippets from my Mail Merge implementation.

    /// set a FieldMergingCallback handler.
    document.MailMerge.FieldMergingCallback = new HandleHtmlContent();

    /// implementation of IFieldMergingCallback.FieldMerging
    public void FieldMerging(FieldMergingArgs args)

        if (args.DocumentFieldName.ToLower().Contains("html"))
            FieldMergeField field = args.Field;

            // Insert the text for this merge field as HTML data, using DocumentBuilder.
            DocumentBuilder builder = new DocumentBuilder(args.Document);
            string htmlContent;

            if (field.TextBefore != null)

            htmlContent = args.FieldValue as string;

            if (htmlContent == null)
                htmlContent = string.Empty;

            builder.InsertHtml(htmlContent, true);

            // The HTML text itself should not be inserted.
            // We have already inserted it as an HTML.
            args.Text = "";



Please refer to the following section of documentation:
Outputting Expression Results

I think, the following code will help you to insert HTML during LINQ report building process.

DataTable dataTable = new DataTable();

// Init a data row with only one of the fields specified, so the other one is null.
DataRow dataRow = dataTable.NewRow();
dataRow["Name"] = "John";

// Init a template.
DocumentBuilder builder = new DocumentBuilder();

// This will print "John" without any special formatting, since the value is not null.
builder.Writeln("Dear <<[Util.HighlightIfNull(Name)] -html>>!");

// This will print "Unspecified" using bold and italic font settings, since the value is null.
builder.Writeln("Dear <<[Util.HighlightIfNull(LastName)] -html>>!");

// The same as above, but this time a custom value to be used for highlighting (i.e. "Last Name") is provided.
builder.Writeln("Dear <<[Util.HighlightIfNull(LastName, \"Last Name\")] -html>>!");

ReportingEngine engine = new ReportingEngine();
engine.KnownTypes.Add(typeof(Util)); // Need this, since we are going to access static members of the Util class.

engine.BuildReport(builder.Document, dataRow);


public class Util
    public static string HighlightIfNull(string value, string defaultValue = "Unspecified")
        if (!string.IsNullOrEmpty(value))
            return value;

        // Apply custom formatting for a missing value using HTML.
        return string.Format("<b><i>{0}</i></b>", defaultValue);

Looks like I missed the “html” switch when I went through the documentation.
It works great.
Thanks a bunch.


It is great that you were able to find what you were looking for. Please let us know any time you have any further queries.