This tutorial shows how to create an ASP.NET Core Web application with Docker support that uses ServerTextControl TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
ServerTextControl Class
The ServerTextControl class implements a component that provide high-level text processing features for server-based applications.

Creating the Application

Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the .NET 6 SDK.

  1. In Visual Studio 2022, create a new project by choosing Create a new project.

  2. Select ASP.NET Core Web App (Model-View-Controller) as the project template and confirm with Next.

  3. Choose a name for your project and confirm with Next.

  4. In the next dialog, choose .NET 6 (Long-term support) as the Framework, disable Configure for HTTPS for effortless testing, do not check Enable Docker and confirm with Create.

    Creating the .NET 6 project

Adding the NuGet Package

  1. In the Solution Explorer, select your created project and choose Manage NuGet Packages... from the Project main menu.

    Select Text Control Offline Packages from the Package source drop-down.

    Install the latest versions of the following package:

    • TXTextControl.TextControl.ASP.SDK

    ASP.NET Core Web Application

Using ServerTextControl and MailMerge

  1. Find the HomeController.cs file in the Controllers folder. Replace the Index() method with the following code:

    public IActionResult Index() {
    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
    // adding static text
    TXTextControl.Selection sel = new TXTextControl.Selection();
    sel.Text = "Welcome to Text Control\r\n";
    sel.Bold = true;
    tx.Selection = sel;
    // adding merge fields
    TXTextControl.DocumentServer.Fields.MergeField mergeField =
    new TXTextControl.DocumentServer.Fields.MergeField() {
    Text = "{{company}}",
    Name = "company",
    TextBefore = "Company name: "
    // alternatively load a template
    //TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings() {
    // ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord
    //tx.Load("template.docx", TXTextControl.StreamType.WordprocessingML, ls);
    // merge fields with MailMerge engine
    using (TXTextControl.DocumentServer.MailMerge mailMerge =
    new TXTextControl.DocumentServer.MailMerge()) {
    mailMerge.TextComponent = tx;
    mailMerge.MergeJsonData("[{\"company\": \"Text Control, LLC\" }]");
    // return result as HTML
    string result = "";
    tx.Save(out result, TXTextControl.StringStreamType.HTMLFormat);
    // alternatively save as PDF
    //byte[] baPdf;
    //tx.Save(out baPdf, TXTextControl.BinaryStreamType.AdobePDF);
    ViewBag.Document = result;
    return View();
    view raw test.cs hosted with ❤ by GitHub

Displaying the Results

  1. Find the Index.cshtml file in the Views -> Home folder. Replace the complete file with the following code:

    ViewData["Title"] = "Home Page";
    view raw test.cshtml hosted with ❤ by GitHub

Creating the Dockerfile

A Docker container image is a lightweight, self-contained, executable software package that contains everything needed to run an application: code, runtime, system tools, system libraries, and settings.

By reading the instructions, a Docker image is automatically created based on a Docker file. The following steps are required in order to prepare for a build process:

  1. Create a new folder named docker-test that contains the following sub-folders and files:

    • Folder named app
    • A text file named Dockerfile (no extension)
  2. In Visual Studio with the application opened that should be deployed, right-click the project in the Solution Explorer and choose Publish.

    In the opened page Publish, select Folder and confirm with Next.

    Creating the Web API

  3. Confirm the location and click Finish. A profile has been created. Close the dialog by clicking Close.

    Creating the Web API

  4. Click on Show all settings to open the Publish dialog. In the opened dialog, select win-x64 as the Target Runtime and confirm with Save.

    Creating the Web API

  5. Click Publish to start the publishing process.

  6. Copy the complete content of the publish folder to the newly created app folder from step 1.

  7. Open the Dockerfile in a text editor such as Visual Studio Code. The Dockerfile script creates a Windows Server container with all requirements including .NET Core run-times and Visual C++ Redistributables.

    Copy the following code to your Dockerfile:

    # Copy the application from folder "app" to "C:\app" on container machine
    COPY app/ /app
    SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
    RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    Invoke-WebRequest "" -OutFile "vc_redist.x64.exe"; \
    Start-Process "vc_redist.x64.exe" -ArgumentList "/passive" -wait -Passthru; \
    Remove-Item -Force vc_redist.x64.exe;
    WORKDIR /app
    EXPOSE 80
    ENTRYPOINT ["dotnet", "MyDockerTXApp.dll"]
    view raw dockerfile hosted with ❤ by GitHub

    Make sure to change the name of the ENTRYPOINT dll to the match the assembly name of your created application.

Creating the Docker Image

In order to create the image, use the following commands:

  1. Assume that you have installed Docker for Windows, open a PowerShell command window with explicit administrator rights and change to the directory where you created the folder docker-test.

    Creating the Web API

  2. Type in the following command to build the Docker image based on the Dockerfile in the same directory:

    docker build -t txcore .

    Creating the Web API

Running the Docker Container

  1. Start the container with the following command:

    docker run -it --rm -p 5000:80 -e ASPNETCORE_URLS=http://+:80 --name aspnetcore_sample txcore

In the Docker Dashboard, you can see the running container listening on port 5000:

Creating the Web API

Open a browser and navigate to http://localhost:5000 to see your deployed web application.

Creating the Web API