Products Technologies Demo Docs Blog Support Company

Merging a Document with 3 Lines of Code: The New MailMerge Class

TX Text Control Server for ASP.NET (incl. Windows Forms) 14.0 ships with a new class that allows documents to be easily merged. A template is a collection of content, including variable merge fields. A merge field is a named region in a document that is possibly formatted. During the compilation process, the actual field values are substituted for the corresponding text fields. These templates can be created using MS Word, OpenOffice or the new shipped TX Template Designer. The MailMerge…

Merging a Document with 3 Lines of Code: The New MailMerge Class

TX Text Control Server for ASP.NET (incl. Windows Forms) 14.0 ships with a new class that allows documents to be easily merged. A template is a collection of content, including variable merge fields. A merge field is a named region in a document that is possibly formatted. During the compilation process, the actual field values are substituted for the corresponding text fields. These templates can be created using MS Word, OpenOffice or the new shipped TX Template Designer.

The MailMerge class is a .NET component that can be easily created dynamically or dropped on a web or Windows form. The documentation explain in detail how to create such an application in very easy steps. In the remainder of this blog post, I would like to explain the advantages of this component.

TX Text Control .NET for Windows Forms contains a collection for the TextFields or ApplicationFields, which are compatible to the fields of MS Word. All steps that are necessary to merge a template using TX Text Control .NET for Windows Forms are encapsulated in this new component.

All you have to do is to load a template, pass the merge data and to save the merged document.

mailMerge1.LoadTemplate(Server.MapPath("template.docx"), TXTextControl.DocumentServer.FileFormat.WordprocessingML);
mailMerge1.Merge(mergeData, true);
mailMerge1.SaveDocument(Server.MapPath("results.pdf"), TXTextControl.StreamType.AdobePDF, saveSettings);

The MailMerge component matches the contained merge field names automatically with the database column names and merges the template with the appropriate data automatically. For each data row in the passed data table, a document is created. These documents can be saved separately or they can be merged into one document that can be saved at once.

After each data row, an event is fired that enables you to save the current document. The following illustration shows the template with the merge fields and the ready merged PDF document at the right:

Mail Merge Process

The MailMerge component contains some more nice features. I will be explaining these in my next blog entries. One of these interesting features are repeating blocks. These blocks allow you to define an area in your template that should be repeated based on the number of data rows in a separately passed data object.

Try out the new MailMerge class yourself by downloading a TX Text Control Server for ASP.NET (incl. Windows Forms) trial version now:

TX Text Control .NET Server

Feel free to contact me, if you would like to discuss the possibilities.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

ASP.NETBlazorASP.NET Core

TX Text Control for Blazor: Mail Merge Integration Tutorial

This tutorial shows how to integrate the TX Text Control MailMerge component into a Blazor application using the TX Text Control .NET Server.


ASP.NETASP.NET CoreMail Merge

Mail Merge: Skipping Records During the Merge Process in .NET C#

This article shows how to skip records during the merge process in .NET C# using the MailMerge class of the Text Control Reporting engine.


ASP.NETASP.NET CoreMail Merge

Mail Merge MS Word DOCX Documents and Convert to PDF in .NET C#

This article shows how to merge data into MS Word DOCX documents and convert them to PDF using TX Text Control .NET Server.


ASP.NETASP.NET CoreMail Merge

Merging Self-Calculating Business Objects with TX Text Control MailMerge in C#

This article shows how to merge self-calculating business objects with TX Text Control MailMerge in C#. The sample shows how to merge a list of products with a total sum.


ASP.NETDigital SignatureDocument Viewer

Use Case: Create, Deploy and Process Insurance Claim Forms

Digital forms processing with electronic signatures offers several benefits that streamline and enhance administrative tasks. This article outlines a typical use case of an insurance claim form…