# ASP.NET MVC Document Viewer

> Show documents in an ASP.NET MVC app on the .NET Framework: TXTextControl.Web.DocumentViewer, Assembly and bin64 references, licenses.licx and annotations.

- **Product:** TX Text Control .NET Server
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET Server > Integration Guide > ASP.NET on .NET Framework > ASP.NET MVC Document Viewer
- **2342 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/mvc-viewer/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/mvc-viewer/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/mvc-viewer/llms-full.txt

---

Existing ASP.NET MVC 5 applications on the .NET Framework display documents with the same Document Viewer and HTML helper as ASP.NET Core applications. What differs is how TX Text Control gets into the project: the viewer package comes from NuGet, while the engine assemblies are referenced from the installation folder and licensed with a *licenses.licx* file. The steps below build such an application in Visual Studio 2022 with .NET Framework 4.8 and load a comment annotation into the viewer.

**Legacy technology.** This setup runs on Windows only and uses the Classic engine of the Windows setup. New applications use [ASP.NET Core](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-viewer/aspnet-core/llms-full.txt) with the NuGet packages of the Core engine.

### Prerequisites

- Visual Studio 2022 and .NET Framework 4.8.
- The Windows setup of TX Text Control .NET Server 34.0, trial or full version. It installs the assemblies to `C:\Program Files\Text Control GmbH\TX Text Control 34.0.NET Server for ASP.NET\` and the **Text Control Offline Packages** package source.

The finished sample of this tutorial is installed with the setup in `%USERPROFILE%\Documents\TX Text Control 34.0.NET Server for ASP.NET\CSharp\MVC\viewer\`.

Unlike the Document Editor, the viewer needs no TX TextControl Service, but it needs the TX Text Control assemblies that you reference in the project below. The README of the package says that in ASP.NET MVC the backend of the viewer is already set up, so the project needs no middleware or route of its own.

### Create the Project

1. In Visual Studio 2022, choose **Create a new project**.
2. Select **ASP.NET Web Application (.NET Framework)** as the project template and confirm with **Next**.
3. Enter a project name, select **.NET Framework 4.8** as the **Framework** and confirm with **Create**.
4. In the next dialog, choose **MVC** as the project template and confirm with **Create**.

    ![The Create a new ASP.NET Web Application dialog of Visual Studio with the MVC template selected and only MVC checked under Add folders & core references.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-server/aspnet-template-mvc.18b14a9c.webp)

### Install the NuGet Package

1. In **Solution Explorer**, select the project and choose **Manage NuGet Packages...** from the **Project** menu.
2. Select **Text Control Offline Packages** or **nuget.org** as the **Package source**.
3. Search for `txtextcontrol.web.documentviewer` and install the latest version of `TXTextControl.Web.DocumentViewer`.

Its .NET Framework 4.5 build depends on `Microsoft.AspNet.Mvc` 5.3.0, `Newtonsoft.Json` 13.0.1 and `System.Net.Http` 4.3.4, which NuGet installs with it. The package doesn't contain the TX Text Control engine: you add it in the next step. A package from nuget.org requires the trial version of TX Text Control .NET Server on the development machine.

### Add the TX Text Control References

1. With the project selected in **Solution Explorer**, choose **Project > Add Project Reference...** to open the **Reference Manager**, and click **Browse...**.
2. In the installation folder, open the *Assembly* folder and select these assemblies:
    - *TXDocumentServer.dll*
    - *TXTextControl.dll*
    - *TXTextControl.Server.dll*
3. Repeat the step for these files from the *Assembly\\bin64* folder:
    - *tx34.dll*
    - *tx34\_ic.dll*
    - *tx34\_tls.dll*
4. Close the **Reference Manager** with **OK**.

The *Assembly\\bin64* folder holds the 64-bit files, and *Assembly\\bin* holds the 32-bit files of the same names. A 64-bit application needs the files from *bin64*, a 32-bit application the files from *bin*.

### Add the License File

Applications on the .NET Framework license TX Text Control with a *licenses.licx* file, which the .NET license compiler reads when the project is built.

1. With the project selected, choose **Project > Add New Item...**.
2. Select **Text File**, name it *licenses.licx* and click **Add**.

    ![The Add New Item dialog of Visual Studio with the Text File template selected and licenses.licx entered as the name.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-server/add-item-licenses-licx.a57aba29.webp)
3. Paste the following line into the file and save it:

    ```text
    TXTextControl.ServerTextControl, TXTextControl.Server, Version=34.0.1900.500, Culture=neutral, PublicKeyToken=6b83fe9a75cfb638
    ```

The line names the licensed class, its assembly and the full version of the assembly. Since version 30.0, the full version is required; without it, an older installed version can be used, which ends in a license error. After an upgrade, change the version, close and reopen Visual Studio and rebuild. See [A Control Could Not Be Licensed](https://docs.textcontrol.com/tx-text-control-dotnet-server/troubleshooting/licensing/#a-control-could-not-be-licensed).

### Add the Viewer to the View

Open *Index.cshtml* in the *Views/Home* folder and replace its complete content with the following code:

```cshtml
@using TXTextControl.Web.MVC.DocumentViewer
@using System.Text

<div style="width: 800px; height: 600px;">

@Html.TXTextControl().DocumentViewer(settings => {
    settings.DocumentData = Convert.ToBase64String(
        Encoding.ASCII.GetBytes("<strong>Sample Content</strong>"));
    settings.Dock = DocumentViewerSettings.DockStyle.Fill;
}).Render()

</div>

<script>

    var jsonAnnotations = '[[{"pen":{"type":"comment","objectWidth":32,"objectHeight":32},"user":"Unknown User","location":{"x":127,"y":50},"time":1658908087097,"comments":[{"comment":"Welcome to Text Control","user":"Unknown User","date":1658908100339,"id":"c8d818ce-ff1e-4c0c-b78c-6ba95a98dede","status":"none"}],"id":"feed80ff-1c94-4abf-9838-3e833faa4092","status":"Accepted"}]]';

    window.addEventListener("documentViewerLoaded", function () {
        TXDocumentViewer.annotations.showToolbar(true);
        TXDocumentViewer.annotations.load(jsonAnnotations);
    });

</script>
```

The view works as follows:

- `@using TXTextControl.Web.MVC.DocumentViewer` imports the namespace of the HTML helper and of [DocumentViewerSettings](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-web-mvc-documentviewer/documentviewersettings/llms-full.txt).
- [`Html.TXTextControl().DocumentViewer()`](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-web-mvc-documentviewer/controlsfactory/documentviewer-method/llms-full.txt) creates the viewer, and `Render()` writes it into the page.
- [DocumentData](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-web-mvc-documentviewer/documentviewersettings/documentdata-property/llms-full.txt) holds the document as a Base64-encoded string, here a short HTML string.
- [Dock](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-web-mvc-documentviewer/documentviewersettings/dock-property/llms-full.txt) set to `Fill` makes the viewer fill the `div` of 800 by 600 pixels.
- When the `documentViewerLoaded` event fires, [annotations.showToolbar](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript-document-viewer/annotations/showtoolbar-method/llms-full.txt) shows the annotation toolbar and [annotations.load](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript-document-viewer/annotations/load-method/llms-full.txt) loads a comment from the JSON string.

### Run the Application

Press **F5** to build and start the application. The home page shows the viewer with the text "Sample Content", the annotation toolbar and a comment with the text "Welcome to Text Control".

### Load a Document From a File

To show a file of the web application, set [DocumentPath](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-web-mvc-documentviewer/documentviewersettings/documentpath-property/llms-full.txt) instead of `DocumentData`. In an MVC 5 view, `Server.MapPath` turns an application path into the physical path. Copy a document to *App\_Data/Documents* and use this helper call:

```cshtml
@using TXTextControl.Web.MVC.DocumentViewer

@Html.TXTextControl().DocumentViewer(settings => {
    settings.DocumentPath = Server.MapPath("~/App_Data/Documents/nda.tx");
    settings.Dock = DocumentViewerSettings.DockStyle.Fill;
}).Render()
```

The settings, the JavaScript API, annotations, forms and signatures of the viewer are the same as in ASP.NET Core. The [Document Viewer](https://docs.textcontrol.com/tx-text-control-dotnet-server/document-viewer/llms-full.txt) section describes them.

### Next Steps

- [ASP.NET MVC Mail Merge](https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/mvc-mail-merge/llms-full.txt): create the documents the viewer shows on the server.
- [Web Forms Document Viewer (Legacy)](https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/web-forms-viewer/llms-full.txt): the older viewer control of Web Forms.
- [.NET Framework Applications](https://docs.textcontrol.com/tx-text-control-dotnet-server/deployment/windows/dotnet-framework/llms-full.txt): the files to deploy with the application.
- [ASP.NET Core](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-viewer/aspnet-core/llms-full.txt): the same viewer in ASP.NET Core.

---

## Nearby

- **Previous:** [ASP.NET MVC Document Editor](https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/mvc-editor/llms-full.txt)
- **Next:** [ASP.NET MVC Mail Merge](https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/mvc-mail-merge/llms-full.txt)
