TX Text Control .NET for Windows Forms

Merge Method

Method|Introduced in 14.0
Namespace
TXTextControl.DocumentServer
Package
TXTextControl.TextControl.WinForms.SDK as TXDocumentServer.dll from the private NuGet feed or Text Control Offline Packages

Description

Merges given data into the loaded document template. The supported format of the merge fields can be found in the ASP.NET User's Guide.

Syntax

Merge(DataTable, bool)

Merges the loaded template with the data of a specific System.Data.DataTable. The second parameter specifies whether the single documents should be merged into one document or splitted into separate documents.

public void Merge(DataTable mergeData, bool append);
ParameterDescription
mergeData

Specifies a System.Data.DataTable that contains the merge data.

append

Specifies whether the single documents should be merged into one document or split into separate documents.

Merge(DataTable)

Does the same as Merge(System.Data.DataTable mergeData, bool append) with parameter “append” set to true.

public void Merge(DataTable mergeData);
ParameterDescription
mergeData

Specifies a System.Data.DataTable that contains the merge data.

Merge(bool)

Merges data into the template using a data base connection given through a data source configuration file or data source configuration XML data. (See also ReportDataSourceConfigFile property and ReportDataSourceConfig property)

public void Merge(bool append);
ParameterDescription
append

Specifies whether the single documents should be merged into one document or split into separate documents.

Merge()

Does the same as method Merge(bool append) with parameter “append” set to true.

public void Merge();

Examples

The following example merges a template that contains two merge fields: name and company.

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

mergeData.Rows.Add(new object[] { "Peter Jackson", "Text Control GmbH" });
mergeData.Rows.Add(new object[] { "Jack Petersen", "The Imaging Source LLC" });

mailMerge1.LoadTemplate("template.doc", TXTextControl.DocumentServer.FileFormat.MSWord);

mailMerge1.Merge(mergeData, true);

TXTextControl.SaveSettings sSettings = new TXTextControl.SaveSettings();
mailMerge1.SaveDocument("results.pdf", TXTextControl.StreamType.AdobePDF, sSettings);

The following example uses Merge in a focused Mail Merge workflow. The created object is then available to the surrounding document workflow.

mailMerge.Merge(new System.Data.DataTable(), true);
Console.WriteLine("Mail Merge is ready for use.");