Products Technologies Demo Docs Blog Support Company

Using the DataSourceManager to Merge Templates

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

Using the DataSourceManager to Merge Templates

The reporting engine TXTextControl.DocumentServer.MailMerge class supports various types of data sources that can be used to merge MS Word compatible documents with data. Supported data sources include DataSets, DataTables, Json objects, hierarchical IEnumerable objects and single business objects.

The TXTextControl.DocumentServer.DataSources.DataSourceManager class encapsulates the complete handling, logic and ready-to-use dialog boxes for reporting template creation tasks. Essentially, the DataSourceManager provides all information required to create a fully-featured template designer. Like with MailMerge, a data source can be loaded from a DataSet, DataTable, Json, an object or XML. The following diagram shows the classes in detail:

TX Text Control DataSourceManager

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 TXTextControl.DocumentServer.MailMerge.BlockRowMerged event.

The following code is using an instance of TXTextControl.ServerTextControl class and the TXTextControl.DocumentServer.DataSources.DataSourceManager class to merge XML data into a template:

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.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.DocumentServer.DataSources.DataSourceManager Class
  • TXTextControl.DocumentServer.MailMerge.BlockRowMerged Event
  • TXTextControl.DocumentServer.MailMerge Class
  • TXTextControl.ServerTextControl 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.

See Reporting products

Related Posts

ASP.NETReportingPDF

.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…


ASP.NETReportingASP.NET Core

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…


ASP.NETReportingASP.NET Core

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…


ActiveXASP.NETReporting

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.


AngularJavaScriptReporting

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.