# Getting Started: ServerTextControl and MailMerge in a .NET 8 Console Application on Linux with Docker and WSL

> This article shows how to create a .NET 8 console application on Linux using Docker and WSL that uses the ServerTextControl to create a document and MailMerge to merge JSON data into the document. The document is saved as a PDF file.

- **Author:** Bjoern Meyer
- **Published:** 2025-03-12
- **Modified:** 2025-11-16
- **Description:** This article shows how to create a .NET 8 console application on Linux using Docker and WSL that uses the ServerTextControl to create a document and MailMerge to merge JSON data into the document. The document is saved as a PDF file.
- **4 min read** (645 words)
- **Tags:**
  - ASP.NET
  - .NET
  - MailMerge
  - Linux
  - Docker
- **Web URL:** https://www.textcontrol.com/blog/2025/03/12/getting-started-servertextcontrol-and-mailmerge-in-a-net-8-console-application-on-linux-with-docker-and-wsl/
- **LLMs URL:** https://www.textcontrol.com/blog/2025/03/12/getting-started-servertextcontrol-and-mailmerge-in-a-net-8-console-application-on-linux-with-docker-and-wsl/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2025/03/12/getting-started-servertextcontrol-and-mailmerge-in-a-net-8-console-application-on-linux-with-docker-and-wsl/llms-full.txt

---

> ### Prerequisites
> 
> You need to download and install the trial version of TX Text Control .NET Server.
> 
> - [Download Trial Version](https://www.textcontrol.com/product/tx-text-control-dotnet-server/download/)  
>     Setup download and installation required.

### Introduction

This tutorial shows how to use Visual Studio 2022 to create an .NET 8 console application that uses the ServerTextControl and MailMerge classes from TX Text Control .NET Server. The application is hosted in a Docker container using a Linux base image.

### Creating the Application

Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0).

1. In Visual Studio 2022, create a new project by choosing *Create a new project*.
2. Select *Console App* as the project template and confirm with *Next*.
3. Enter a project name and choose a location to save the project. Confirm with *Next*.
4. Choose *.NET 8.0 (Long Term Support)* as the *Framework*.
5. Enable the *Enable container support* checkbox and choose *Linux* as the *Container OS*.
6. Choose *Dockerfile* for the *Container build type* option and confirm with *Create*.
    
    ![Creating the .NET 8 project](https://s1-www.textcontrol.com/assets/dist/blog/2025/03/12/c/assets/visualstudio1.webp "Creating the .NET 8 project")

#### Adding the NuGet Packages

7. In the *Solution Explorer*, select your created project and choose *Manage NuGet Packages...* from the *Project* main menu. Select **Text Control Offline Packages** as the *Package source*.
    
    Install the following package:
    
    
    - **TXTextControl.TextControl.Core.SDK**
    
    ![ASP.NET Core Web Application](https://s1-www.textcontrol.com/assets/dist/blog/2025/03/12/c/assets/visualstudio2.webp "ASP.NET Core Web Application")

#### Using ServerTextControl and MailMerge

8. Find the *Program.cs* file in the *Solution Explorer* and replace the code with the following code snippet:
    
    ```
    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
    {
        // Create a new ServerTextControl instance
        tx.Create();
    
        // Adding static text with formatting
        TXTextControl.Selection sel = new TXTextControl.Selection
        {
            Text = "Welcome to Text Control\r\n", // Static welcome message
            Bold = true // Apply bold formatting
        };
        tx.Selection = sel;
    
        // Adding a merge field for dynamic data insertion
        TXTextControl.DocumentServer.Fields.MergeField mergeField = new TXTextControl.DocumentServer.Fields.MergeField
        {
            Text = "{{company}}", // Placeholder text in the document
            Name = "company", // Internal name for the merge field
            TextBefore = "Company name: " // Prefix text before the field
        };
    
        // Add the merge field to the document
        tx.ApplicationFields.Add(mergeField.ApplicationField);
    
        // ---- Optionally load a template ----
        // If a predefined document template is available, uncomment the following lines
        /*
        TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings
        {
            ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord // Preserve Word field format
        };
        tx.Load("template.docx", TXTextControl.StreamType.WordprocessingML, ls);
        */
    
        // Perform mail merge using JSON data
        using (TXTextControl.DocumentServer.MailMerge mailMerge = new TXTextControl.DocumentServer.MailMerge())
        {
            mailMerge.TextComponent = tx; // Link MailMerge engine to the text component
    
            // JSON data to be merged into the document
            string jsonData = "[{\"company\": \"Text Control, LLC\" }]";
            mailMerge.MergeJsonData(jsonData); // Merge the provided JSON data
        }
    
        tx.Save("results.pdf", TXTextControl.StreamType.AdobePDF);
    
        Console.WriteLine("Document created: results.pdf");
    }
    ```

#### Run with Docker

9. Select *Container (Dockerfile)* as the startup profile and start the application.
    
    ![Starting the application](https://s1-www.textcontrol.com/assets/dist/blog/2025/03/12/c/assets/container.webp "Starting the application")

#### Run with WSL

For a faster development experience, you can run the application in WSL (Windows Subsystem for Linux).

- Select *WSL* as the startup profile and start the application.
    
    ![Starting the application](https://s1-www.textcontrol.com/assets/dist/blog/2025/03/12/c/assets/wsl.webp "Starting the application")

#### Enable WSL (Windows Subsystem for Linux)

In case you haven't enabled WSL yet, follow these steps:

> **Enable WSL (Windows Subsystem for Linux)**
> 
> 1. Open PowerShell as an administrator.
> 2. Run the following command:
>     
>     ```
>     wsl --install
>     ```
>     
>     This installs the default Linux distribution (usually Ubuntu) and enables necessary features.
> 3. After the installation, restart your computer.
> 
> **Set WSL 2 as the Default Version**
> 
> To set WSL 2 as the default version, follow these steps:
> 
> 1. Open PowerShell as an administrator.
> 2. Run the following command:
>     
>     ```
>     wsl --set-default-version 2
>     ```
> 3. If you haven't installed a Linux distribution yet, you can do so via:
>     
>     ```
>     wsl --install -d Ubuntu
>     ```

---

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

- [Announcing the Official DS Server Docker Image on Docker Hub](https://www.textcontrol.com/blog/2025/05/02/announcing-the-official-ds-server-docker-image-on-docker-hub/llms.txt)
- [Using TX Text Control with Ultra-Minimal Chiseled Linux Containers](https://www.textcontrol.com/blog/2025/03/12/using-tx-text-control-with-ultra-minimal-chiseled-linux-containers/llms.txt)
- [Getting Started: Document Editor with ASP.NET Core and Docker Support with Linux Containers](https://www.textcontrol.com/blog/2025/03/12/getting-started-document-editor-with-asp-net-core-and-docker-support-with-linux-containers/llms.txt)
- [ASP.NET Core: Deploying the TX Text Control 32.0 SP2 Document Editor to Linux](https://www.textcontrol.com/blog/2024/01/22/deploying-tx-text-control-to-linux/llms.txt)
- [ASP.NET Core: Deploying the TX Text Control Document Editor to Linux](https://www.textcontrol.com/blog/2021/10/29/deploying-tx-text-control-to-linux/llms.txt)
