
The source code is contained in the following directory:
Used TX Text Control controls:
Relevant API links:
1. Open Visual Studio 2008 and choose File, New, Project... to open the New Project dialog box.
2. To create a new web project, select Web from the Project types. Select the ASP.NET Web Application as the project type and choose an appropriate name for your project like in the screenshot below. Confirm with OK to create the new web project.

3. Select the default.aspx page in the Solution Explorer and choose Component Designer from the View main menu.
4. Choose Select toolbox items... from the Tools main menu to open the Choose Toolbox Items dialog box. Sort by Namespace and check the ServerTextControl and the MailMerge components from the TXTextControl namespace.

The components should now be visible in the toolbox:

5. Drag and drop both components to the form. It should look like this:

6. Select the MailMerge component and bind the ServerTextControl component to it. This can be done in the Properties window by choosing serverTextControl1 in the TextComponent property.

7. Switch to the design view of the default.aspx page and add a standard button control to the page.
8. Create a sample template like described in this article: Creating templates using TX Template Designer. The following merge fields should exist in this template: title, last_name, address_line_1, state, city, zip. Save the template in the project's folder and name it template.docx.
9. Double-click the button to open the default.aspx.cs code view.
10. Add the following code to the button's click event:
[C#]
// create a new DataTable containing the data for the merge process
DataTable mergeData = new DataTable();
mergeData.Columns.AddRange( new DataColumn[] {
new DataColumn("title"),
new DataColumn("last_name"),
new DataColumn("address_line_1"),
new DataColumn("state"),
new DataColumn("city"),
new DataColumn("zip") } );
// add the data rows
mergeData.Rows.Add( new string[] { "Mr.", "Jackson", "23 Pineville-Matthews-Rd.", "NC", "Charlotte", "28743" } );
mergeData.Rows.Add( new string[] { "Mr.", "Peterson", "233 Jackson-Appel-Rd.", "NC", "Charlotte", "28563" } );
mergeData.Rows.Add( new string[] { "Mr.", "Johnson", "22 Johnson-Rd.", "NC", "Charlotte", "28222" } );
// load the template and start the merge process
mailMerge1.LoadTemplate(Server.MapPath("template.docx"), TXTextControl.DocumentServer.FileFormat.WordprocessingML);
mailMerge1.Merge(mergeData, true);
// save the content in the byte array and pass it to the browser
byte[] data;
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings();
mailMerge1.SaveDocumentToMemory(out data, TXTextControl.BinaryStreamType.AdobePDF, saveSettings);
Response.Clear();
Response.ContentType = "application/pdf";
Response.BinaryWrite(data);
Response.End();
[Visual Basic]
' create a new DataTable containing the data for the merge process
Dim mergeData As New DataTable()
mergeData.Columns.AddRange(New DataColumn() {
New DataColumn("title"),
New DataColumn("last_name"),
New DataColumn("address_line_1"),
New DataColumn("state"),
New DataColumn("city"),
New DataColumn("zip")})
' add the data rows
mergeData.Rows.Add(New String() {"Mr.", "Jackson", "23 Pineville-Matthews-Rd.", "NC", "Charlotte", "28743"})
mergeData.Rows.Add(New String() {"Mr.", "Peterson", "233 Jackson-Appel-Rd.", "NC", "Charlotte", "28563"})
mergeData.Rows.Add(New String() {"Mr.", "Johnson", "22 Johnson-Rd.", "NC", "Charlotte", "28222"})
' load the template and start the merge process
mailMerge1.LoadTemplate(Server.MapPath("template.docx"), TXTextControl.DocumentServer.FileFormat.WordprocessingML)
mailMerge1.Merge(mergeData, True)
' save the content in the byte array and pass it to the browser
Dim data As Byte() = Nothing
Dim saveSettings As New TXTextControl.SaveSettings()
mailMerge1.SaveDocumentToMemory(data, TXTextControl.BinaryStreamType.AdobePDF, saveSettings)
Response.Clear()
Response.ContentType = "application/pdf"
Response.BinaryWrite(data)
Response.End()
11. Call the InitializeComponent() function in the Page_Load event:
[C#]
protected void Page_Load(object sender, EventArgs e)
{
InitializeComponent();
}
[Visual Basic]
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
InitializeComponent()
End Sub
12. Start the application by pressing F5.