Merge fields are pre-formatted in a template and populated with database content during the merge process. Usually, a merge field accepts plain text from a database column field or an XML element value that is formatted with the applied template format.

In some applications, it could be helpful to add a carriage return line feed character to merge fields. This sample shows how to use the FieldMerged event to handle this situation.

This project shows how to insert a carriage return line feed in the following situations:

  • As part of the merge data
  • As part of the merge field
  • As part of the True and False text in IF fields

The following screenshot shows the demo project. The XML data source is displayed in the panel on the right.

MailMerge: MergeFields with CRLFs

In the first field, the CRLF character ("\r\n") is part of the field data (see right panel in the above screenshot). The second field has "\r\n" defined as the TextAfter property and the IF field contains "\r\n" in the TrueText and FalseText properties. These fields need to be handled in the FieldMerged event:

Loading...

The string "\r\n" is simply replaced with the CRLF control character.

Download the sample from GitHub and test it on your own.

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on GitHub.com/TextControl.

Please fork and contribute.

Requirements for This Sample

  • Visual Studio 2012 or better
  • TX Text Control .NET Server for ASP.NET (trial sufficient)