# MailMerge: MergeFields with CRLFs

> TX Text Control MailMerge ignores carriage return and line feed characters in merge field data by default. The FieldMerged event provides a way to detect CRLF sequences in field values, merge data, and IF field conditions, then replace them with actual text breaks in output.

- **Author:** Bjoern Meyer
- **Published:** 2015-09-02
- **Modified:** 2026-07-17
- **Description:** TX Text Control MailMerge ignores carriage return and line feed characters in merge field data by default. The FieldMerged event provides a way to detect CRLF sequences in field values, merge data, and IF field conditions, then replace them with actual text breaks in output.
- **2 min read** (258 words)
- **Tags:**
  - HTML5
  - Reporting
- **Web URL:** https://www.textcontrol.com/blog/2015/09/02/mailmerge-mergefields-with-crlfs/
- **LLMs URL:** https://www.textcontrol.com/blog/2015/09/02/mailmerge-mergefields-with-crlfs/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2015/09/02/mailmerge-mergefields-with-crlfs/llms-full.txt
- **GitHub Repository:** https://github.com/TextControl/TextControl.MailMerge.CRLF

---

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](https://s1-www.textcontrol.com/assets/dist/blog/2015/09/02/a/assets/tx_merge_crlf.webp "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:

```
private void mailMerge1_FieldMerged(object sender,
 TXTextControl.DocumentServer.MailMerge.FieldMergedEventArgs e)
{
 ApplicationField field = e.MailMergeFieldAdapter.ApplicationField;
 field.Text = field.Text.Replace(@"\r\n", "\r\n");
}
```

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

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

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Creating Your First ASP.NET Reporting Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt)
- [Automatically Reconnect to the Server and Recover the Document](https://www.textcontrol.com/blog/2019/09/05/automatically-reconnect-to-the-server-and-recover-the-document/llms.txt)
- [JavaScript API: Working with Merge Fields](https://www.textcontrol.com/blog/2018/03/05/javascript-api-working-with-merge-fields/llms.txt)
- [Technology Preview: Embeddable HTML Widget to integrate Document Editing to Angular, React and other Frameworks](https://www.textcontrol.com/blog/2018/03/01/embeddable-html-widget-for-all-frameworks/llms.txt)
- [Embedding TXTextControl.Web in non-.NET Framework applications like .NET Core and AngularJS](https://www.textcontrol.com/blog/2017/10/23/embedding-txtextcontrol/llms.txt)
- [Sneak Peek X15: Custom Field Overlays in HTML5-based Text Control](https://www.textcontrol.com/blog/2017/06/21/sneak-peek-x15-custom-field-overlays-in-html5-based-text-control/llms.txt)
- [New ASP.NET MVC DocumentViewer Rolled out to the ReportingCloud Portal](https://www.textcontrol.com/blog/2017/04/22/new-aspnet-mvc-documentviewer-rolled-out-to-the-reportingcloud-portal/llms.txt)
- [Updated MVC Sample: Loading Files from the Backstage Menu](https://www.textcontrol.com/blog/2017/04/20/updated-mvc-sample-loading-files-from-the-backstage-menu/llms.txt)
- [ASP.NET MVC: Implementing a Simplistic, Custom Button Bar](https://www.textcontrol.com/blog/2017/03/13/aspnet-mvc-implementing-a-simplistic-custom-button-bar/llms.txt)
- [ASP.NET MVC: Adding Protected Sections to Documents](https://www.textcontrol.com/blog/2017/03/01/aspnet-mvc-adding-protected-sections-to-documents/llms.txt)
- [ASP.NET: Adding Electronic Signatures to Documents](https://www.textcontrol.com/blog/2016/10/12/aspnet-adding-electronic-signatures-to-documents/llms.txt)
- [Setting the Interface and Control's Culture of Web.TextControl](https://www.textcontrol.com/blog/2015/12/16/setting-the-interface-and-controls-culture-of-webtextcontrol/llms.txt)
- [X13: Using IMEs and Localization in Web.TextControl](https://www.textcontrol.com/blog/2015/11/20/x13-using-imes-and-localization-in-webtextcontrol/llms.txt)
- [X13: New Web Forms DocumentViewer Style](https://www.textcontrol.com/blog/2015/11/19/x13-new-web-forms-documentviewer-style/llms.txt)
- [Sneak Peek X13: New Features in Web.TextControl](https://www.textcontrol.com/blog/2015/11/18/sneak-peek-x13-new-features-in-webtextcontrol/llms.txt)
- [HTML5: Display and Handle FormCheckBox Fields](https://www.textcontrol.com/blog/2015/09/22/html5-display-and-handle-formcheckbox-fields/llms.txt)
- [HTML5: Loading Local Documents - Part 2](https://www.textcontrol.com/blog/2015/09/04/html5-loading-local-documents-part-2/llms.txt)
- [Web.TextControl: Can't Connect to the Server?](https://www.textcontrol.com/blog/2015/09/03/webtextcontrol-cant-connect-to-the-server/llms.txt)
- [HTML5: Loading Local Documents Using Pure Javascript](https://www.textcontrol.com/blog/2015/09/01/html5-loading-local-documents-using-pure-javascript/llms.txt)
- [Create Database Excerpt Files from Assemblies](https://www.textcontrol.com/blog/2015/08/25/create-database-excerpt-files-from-assemblies/llms.txt)
- [New Text Control Reporting Online Demo Launched](https://www.textcontrol.com/blog/2015/08/20/new-text-control-reporting-online-demo-launched/llms.txt)
- [New HTML5 Reporting Demo Website Online](https://www.textcontrol.com/blog/2015/08/18/new-html5-reporting-demo-website-online/llms.txt)
- [TextControl.Web: Custom Mail Merge Preview](https://www.textcontrol.com/blog/2015/08/14/textcontrolweb-custom-mail-merge-preview/llms.txt)
- [Web.TextControl Successfully Tested in Project Spartan](https://www.textcontrol.com/blog/2015/04/02/webtextcontrol-successfully-tested-in-project-spartan/llms.txt)
- [Web.TextControl X12: Fully Programmable API](https://www.textcontrol.com/blog/2015/03/09/webtextcontrol-x12-fully-programmable-api/llms.txt)
