Using the DataSourceManager to Merge Templates
This article shows how to use the DataSourceManager to merge data into templates.

The reporting engine TXText
The TXText
But the DataSourceManager cannot only be used to manage data sources for template creation tasks - it can be also used to merge the actual document. The advantage: You can use more direct data sources to pass data to MailMerge including assemblies, XML files and strings and data source configuration files. The main reason for the merge capabilities of the DataSourceManager is to preview templates in a template designer. Therefore, it is not possible to trap MailMerge events such as the TXText
The following code is using an instance of TXText
IList<byte[]> documents;
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
byte[] bTemplate = File.ReadAllBytes("template.tx");
TXTextControl.DocumentServer.DataSources.DataSourceManager dsManager =
new TXTextControl.DocumentServer.DataSources.DataSourceManager();
dsManager.LoadXmlFile("sample_db.xml");
documents = dsManager.Merge(bTemplate, textControl1);
}
The template must be loaded using the internal TX Text Control file format and resulting documents are returned as byte arrays in the internal TX Text Control format.
The DataSourceManager can load data from the following sources:
- Assembly
- DataTable
- DataSet
- DataSourceConfig files
- Json
- Objects
- Single object
- XML file
- XML string
Conclusion: The merge capability of the DataSourceManager is a very powerful tool to manage loaded data sources and to merge data into templates when creating a template designer.
Also See
This post references the following in the documentation:
- TXText
Control. Document Server. Data Sources. Data Source Manager Class - TXText
Control. Document Server. Mail Merge. Block Row Merged Event - TXText
Control. Document Server. Mail Merge Class - TXText
Control. Server Text Control Class
Reporting
The Text Control Reporting Framework combines powerful reporting features with an easy-to-use, MS Word compatible word processor. Users can create documents and templates using ordinary Microsoft Word skills. The Reporting Framework is included in all .NET based TX Text Control products including ASP.NET, Windows Forms and WPF.
Related Posts
.NET C# PDF Generation Techniques: Which Method is Right for Your Project?
This article explains the distinct advantage TX Text Control offers with its true WYSIWYG (What You See Is What You Get) template system, where templates are designed visually, similar to…
Best Practices for Mail Merge and Form Field Processing in ASP.NET Core C#…
This article provides best practices for mail merge and form field processing in ASP.NET Core C# applications using TX Text Control .NET Server. It shows how to use the Document Editor to create…
Advantages of Flow Type Layout Reporting vs. Banded Reporting or PDF…
This article shows the advantages of flow type layout reporting compared to banded reporting or populating PDF placeholders in .NET C#. It explains the differences and the benefits of using a flow…
TX Text Control 32.0 Has Been Released
We are pleased to announce the immediate availability of TX Text Control 32.0 for all platforms including ASP.NET, Windows Forms, WPF and ActiveX.
Getting Started: Angular Document Editor Attributes Explained
This article explains the possible attributes that can be used when initializing the TX Text Control Document Editor for Angular.