Developers need powerful, reliable, and versatile tools for working with Microsoft Word documents. For working with Word documents in DOCX, DOC and RTF formats, TX Text Control is the ideal solution. Whether you need a full-featured document editor or libraries to programmatically manipulate documents, TX Text Control has you covered.

Document Editor

TX Text Control provides an advanced document editor designed specifically for ASP.NET and ASP.NET Core applications. This editor allows users to:

  • Seamlessly edit Word documents: With the same ease as Microsoft Word, open, edit, and save DOCX, DOC, and RTF documents.
  • Utilize rich text features: Add and edit tables, images, headers, footers, and other elements with precision.
  • Working with forms and fields: Create fillable forms with text fields, checkboxes, and drop-down menus for interactive user experiences.

Headless Document Processing

Sometimes you need to programmatically modify or create Word documents without a user interface. TX Text Control's libraries make this possible:

  • Create documents from scratch: Create fully customizable documents, such as invoices, reports, or letters.
  • Modify existing documents: Insert, edit, or delete content programmatically for automation and efficiency.
  • Merge data into templates: Populate Word templates with dynamic data to create personalized documents.
  • Automate workflows: Integrate document editing into back-end workflows for seamless document processing.

Getting Started: Editor

Follow these steps to create an ASP.NET Core application that uses the TX Text Control Document Editor.

Prerequisites

Before you start, make sure you have downloaded the trial version of TX Text Control.

Creating the Application

Make sure that you have downloaded the latest version of Visual Studio 2022, which is included with the .NET 8 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 8 (Long Term Support) as the Framework and confirm with Create.

    Creating the .NET 6 project

Adding the NuGet Package

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

    Package Source

    Select either Text Control Offline Packages or nuget.org as the Package source. Packages in the official Text Control NuGet profile are updated frequently.

    Browse for txtextcontrol.web and Install the latest version of the TXTextControl.Web package.

    ASP.NET Core Web Application

Configure the Application

  1. Open the Program.cs file located in the project's root folder.

    At the very top of the file, insert the following code:

    using TXTextControl.Web;
    view raw test.cs hosted with ❤ by GitHub

    Add the following code after the entry app.UseStaticFiles();:

    // enable Web Sockets
    app.UseWebSockets();
    // attach the Text Control WebSocketHandler middleware
    app.UseTXWebSocketMiddleware();
    view raw test.cs hosted with ❤ by GitHub

Adding the Control to the View

  1. Find the Index.cshtml file in the Views -> Home folder. Replace the complete content with the following code to add the document editor to the view:

    @using TXTextControl.Web.MVC
    @{
    var sDocument = "<html><body><p>Welcome to <strong>Text Control</strong></p></body></html>";
    }
    @Html.TXTextControl().TextControl(settings => {
    settings.UserNames = new string[] { "Tim Typer" };
    }).LoadText(sDocument, TXTextControl.Web.StringStreamType.HTMLFormat).Render()
    <input type="button" onclick="insertTable()" value="Insert Table" />
    <script>
    function insertTable() {
    TXTextControl.tables.add(5, 5, 10, function(e) {
    if (e === true) { // if added
    TXTextControl.tables.getItem(function(table) {
    table.cells.forEach(function(cell) {
    cell.setText("Cell text");
    });
    }, null, 10);
    }
    })
    }
    </script>
    view raw test.cshtml hosted with ❤ by GitHub

Run the Application

  1. Run the application by pressing F5 or by choosing Debug -> Start Debugging from the main menu. You get a full-featured document editor in your ASP.NET Core application.

    Running the application

Non-UI Document Processing

TX Text Control provides a powerful API for programmatically creating, modifying, and manipulating documents. The following tutorial shows how to create a simple .NET console application that uses the TX Text Control to create a document from scratch.

Prerequisites

The following tutorial requires a trial version of TX Text Control .NET Server for ASP.NET.

  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. Choose a name for your project and confirm with Next.

  4. In the next dialog, choose .NET 8 (Long-term support) as the Framework and confirm with Create.

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

Create Documents

  1. Open the Program.cs file located in the project root folder and include this code:

    using TXTextControl;
    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
    {
    tx.Create();
    // Add a paragraph to the document
    TXTextControl.Selection selection = new TXTextControl.Selection(0, 0);
    selection.Text = "Hello Office Open XML!";
    // Set the paragraph format
    selection.ParagraphFormat = new ParagraphFormat()
    {
    Alignment = HorizontalAlignment.Center,
    BackColor = System.Drawing.Color.LightGray,
    Frame = Frame.BottomLine,
    FrameLineColor = System.Drawing.Color.Red,
    FrameStyle = FrameStyle.Double,
    FrameLineWidth = 10
    };
    // Set the font format
    selection.FontSize = 240; // 240 twips = 12 pt
    selection.FontName = "Arial";
    selection.Bold = true;
    // Apply the changes to the document
    tx.Selection = selection;
    // Save the document
    tx.Save("results.docx", TXTextControl.StreamType.WordprocessingML);
    }
    view raw test.cs hosted with ❤ by GitHub

This creates a new document and adds a paragraph with specific formatting, including borders, alignment, and character style. The document is then saved in DOCX format.

MS Word Document

Learn More

This article provides a guide on using TX Text Control to create MS Word DOCX including headers, footers, and tables.

Create Word Document with .NET C#

Conclusion

TX Text Control provides robust and versatile tools for seamlessly handling Word documents in ASP.NET and ASP.NET Core applications. Whether your project requires a feature-rich, interactive document editor for users to create and modify content in real time, or powerful libraries for back-end, non-UI document processing tasks such as programmatically creating, editing, or converting documents, TX Text Control provides comprehensive solutions. By combining ease of use with advanced functionality, TX Text Control ensures that developers have everything they need to implement sophisticated document management features in their applications.