# MailMerge: Creating Separate Documents from Multiple Data Records

> The MailMerge.Merge method combines data records into documents. Setting the append parameter to false produces a separate document per record. The DataRowMerged event exposes each result through DataRowMergedEventArgs, allowing export via a temporary ServerTextControl instance.

- **Author:** Bjoern Meyer
- **Published:** 2014-12-11
- **Modified:** 2026-07-17
- **Description:** The MailMerge.Merge method combines data records into documents. Setting the append parameter to false produces a separate document per record. The DataRowMerged event exposes each result through DataRowMergedEventArgs, allowing export via a temporary ServerTextControl instance.
- **3 min read** (482 words)
- **Tags:**
  - Reporting
- **Web URL:** https://www.textcontrol.com/blog/2014/12/11/mailmerge-creating-separate-documents-from-multiple-data-records/
- **LLMs URL:** https://www.textcontrol.com/blog/2014/12/11/mailmerge-creating-separate-documents-from-multiple-data-records/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2014/12/11/mailmerge-creating-separate-documents-from-multiple-data-records/llms-full.txt

---

By default, the [Merge](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.merge.method.htm) method of the [MailMerge](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.class.htm) class, merges all records into a single document.

The second parameter *append* specifies whether the single documents should be merged into one document or splitted into separate documents.

```
public void Merge(System.Data.DataTable mergeData, bool append);
```

When connected to a *TextComponent* such as the visual *TXTextControl.TextControl*, the resulting document is loaded into the connected Text Control. In case the *Merge* method has been used with the *append* parameter *false*, only the last created document is loaded back into the Text Control.

In order to access each single created document, the [DataRowMerged](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.datarowmerged.event.htm) event can be used to save the return value of this event. The event arguments [DataRowMergedEventArgs](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.datarowmergedeventargs.class.htm) return the merged document in the internal TX Text Control format that can be accessed using the [MergedRow](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.documentserver.mailmerge.datarowmergedeventargs.mergedrow.property.htm) property.

The following sample shows how to use the event by merging the following simple template consisting of two merge fields:

![MailMerge: Creating separate documents from multiple data records](https://s1-www.textcontrol.com/assets/dist/blog/2014/12/11/a/assets/template.webp "MailMerge: Creating separate documents from multiple data records")As a data source, a simple DataSet with one DataTable is used. Before the Merge method is called with the *append* parameter set to *false*, the *DataRowMerged* event is attached:

```
DataTable dt = new DataTable();
dt.Columns.Add("company");
dt.Columns.Add("name");

dt.Rows.Add(new string[] { "Text Control", "Peter Jackson" });
dt.Rows.Add(new string[] { "Microsoft", "Sue Williamson" });
dt.Rows.Add(new string[] { "Google", "Peter Gustavsson" });

mailMerge1.LoadTemplate(Server.MapPath("template.docx"),
    TXTextControl.DocumentServer.FileFormat.WordprocessingML);

mailMerge1.DataRowMerged += mailMerge1_DataRowMerged;
mailMerge1.Merge(dt, false);
```

In the *DataRowMerged* event, each merged record is loaded into a temporary *ServerTextControl* and saved as HTML which is then sent back to the browser using *HttpResponse*:

```
void mailMerge1_DataRowMerged(object sender,
    TXTextControl.DocumentServer.MailMerge.DataRowMergedEventArgs e)
{
    string htmlDocument = "";

    using (TXTextControl.ServerTextControl tx =
        new TXTextControl.ServerTextControl())
    {
        tx.Create();
        tx.Load(e.MergedRow,
            TXTextControl.BinaryStreamType.InternalUnicodeFormat);
        tx.Save(out htmlDocument, TXTextControl.StringStreamType.HTMLFormat);
    }

    Response.Write(htmlDocument);
    Response.Write("<hr />");
}
```

The resulting HTML shows the 3 merged records divided by an horizontal rule:

![MailMerge: Creating separate documents from multiple data records](https://s1-www.textcontrol.com/assets/dist/blog/2014/12/11/a/assets/results.webp "MailMerge: Creating separate documents from multiple data records")Try this on your own and download the [sample project for Visual Studio 2012](https://s1-www.textcontrol.com/assets/dist/blog/2014/12/11/a/assets/merge_single_records.zip). At least, a trial version of TX Text Control .NET Server X11 is required.

---

## 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

- [C# Document Generation: A Developer's Guide for .NET](https://www.textcontrol.com/blog/2026/07/08/csharp-document-generation-developer-guide-for-dotnet/llms.txt)
- [Convert SSRS RDL Reports to DOCX and TX Text Control Templates in .NET C#](https://www.textcontrol.com/blog/2026/06/22/convert-ssrs-rdl-reports-to-docx-and-tx-text-control-templates-in-dotnet-csharp/llms.txt)
- [.NET C# PDF Generation Techniques: Which Method is Right for Your Project?](https://www.textcontrol.com/blog/2024/10/30/net-csharp-pdf-generation-techniques-which-method-is-right-for-your-project/llms.txt)
- [Best Practices for Mail Merge and Form Field Processing in ASP.NET Core C# Applications](https://www.textcontrol.com/blog/2024/07/30/best-practices-for-mail-merge-and-form-field-processing-in-asp-net-core-csharp-applications/llms.txt)
- [Advantages of Flow Type Layout Reporting vs. Banded Reporting or PDF Template Engines in .NET C#](https://www.textcontrol.com/blog/2024/07/29/advantages-of-flow-type-layout-reporting-vs-banded-reporting-or-pdf-template-engines-in-net-c-sharp/llms.txt)
- [TX Text Control 32.0 Has Been Released](https://www.textcontrol.com/blog/2023/09/13/tx-text-control-320-has-been-released/llms.txt)
- [Getting Started: Angular Document Editor Attributes Explained](https://www.textcontrol.com/blog/2023/02/01/getting-started-angular-document-editor-attributes-explained/llms.txt)
- [Getting Started: Programming the Angular Document Editor using JavaScript](https://www.textcontrol.com/blog/2023/01/30/getting-started-programming-the-angular-document-editor-using-javascript/llms.txt)
- [Getting Started: Loading and Saving Documents using Angular](https://www.textcontrol.com/blog/2023/01/30/loading-and-saving-documents-using-angular/llms.txt)
- [TX Text Control 31.0 and TX Spell .NET 10.0 Have Been Released](https://www.textcontrol.com/blog/2022/09/07/tx-text-control-31-released/llms.txt)
- [TX Text Control 30.0 and TX Spell .NET 9.0 Have Been Released](https://www.textcontrol.com/blog/2021/11/29/tx-text-control-30-released/llms.txt)
- [TX Text Control X19 and TX Spell 8.0 Have Been Released](https://www.textcontrol.com/blog/2020/12/02/tx-text-control-x19-released/llms.txt)
- [TX Text Control for Angular X18 Published](https://www.textcontrol.com/blog/2020/03/18/tx-text-control-for-angular-x18-published/llms.txt)
- [MVC NuGet Packages for X18 Published](https://www.textcontrol.com/blog/2020/03/17/mvc-nuget-packages-for-x18-published/llms.txt)
- [TX Text Control X18 has been Released](https://www.textcontrol.com/blog/2020/03/16/tx-text-control-x18-released/llms.txt)
- [Impressions from NDC London 2020](https://www.textcontrol.com/blog/2020/02/01/impressions-from-ndc-london-2020/llms.txt)
- [Sneak Peek X18: Form Field Conditional Instructions](https://www.textcontrol.com/blog/2020/01/03/sneak-peek-x18-form-field-conditional-instructions/llms.txt)
- [DocumentViewer: New Two Page View Mode](https://www.textcontrol.com/blog/2020/01/02/documentviewer-new-two-page-view-mode/llms.txt)
- [Creating Your First ASP.NET Reporting Application](https://www.textcontrol.com/blog/2020/01/01/creating-your-first-aspnet-reporting-application/llms.txt)
- [What a Year! 2019 Recap and Outlook 2020](https://www.textcontrol.com/blog/2019/12/23/what-a-year-2019-recap-and-outlook-2020/llms.txt)
- [MailMerge Class Settings Explained](https://www.textcontrol.com/blog/2019/12/05/mailmerge-settings-explained/llms.txt)
- [Impressions from DDC in Cologne](https://www.textcontrol.com/blog/2019/12/02/impressions-from-ddc-in-cologne/llms.txt)
- [See Text Control at DDC in Cologne](https://www.textcontrol.com/blog/2019/11/24/see-text-control-at-ddc-in-cologne/llms.txt)
- [Impressions from DEVintersection Fall 2019](https://www.textcontrol.com/blog/2019/11/22/impressions-from-devintersection-fall-2019/llms.txt)
- [Impressions from TechBash 2019](https://www.textcontrol.com/blog/2019/11/14/impressions-from-techbash-2019/llms.txt)
