# MVC DocumentViewer: Loading Documents

> The TX Text Control MVC DocumentViewer supports three document loading methods: from server-side files via the DocumentPath property, from Base64-encoded data using the DocumentData property with ServerTextControl format conversion, or dynamically from JavaScript through Ajax.

- **Author:** Bjoern Meyer
- **Published:** 2018-07-03
- **Modified:** 2026-03-05
- **Description:** The TX Text Control MVC DocumentViewer supports three document loading methods: from server-side files via the DocumentPath property, from Base64-encoded data using the DocumentData property with ServerTextControl format conversion, or dynamically from JavaScript through Ajax.
- **3 min read** (424 words)
- **Tags:**
  - ASP.NET
  - Document Viewer
  - MVC
- **Web URL:** https://www.textcontrol.com/blog/2018/07/03/mvc-documentviewer-loading-documents/
- **LLMs URL:** https://www.textcontrol.com/blog/2018/07/03/mvc-documentviewer-loading-documents/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2018/07/03/mvc-documentviewer-loading-documents/llms-full.txt

---

The [MVC DocumentViewer](https://www.nuget.org/packages/TXTextControl.Web.DocumentViewer/) is typically used to display documents and resulting reports in web applications. Documents can be loaded from files resides physically server-side, from data or from JavaScript.

This article describes these three different ways to load documents into the DocumentViewer.

1. **Loading documents from files**
    
    Documents that resides physically on the server can be loaded directly from the HTML Helper view code. In order to load a document from a physical file, the DocumentPathproperty must point to a supported file type on the server.
    
    ```
    @Html.TXTextControl().DocumentViewer(settings =>
    {
       settings.DocumentPath = Server.MapPath("~/App_Data/Documents/car_insurance.tx");
       settings.Dock = DocumentViewerSettings.DockStyle.Fill;
       settings.IsSelectionActivated = true;
       settings.ShowThumbnailPane = true;
    }).Render()
    ```
    
    [See this live ](https://demos.textcontrol.com/chapter/topic/DocumentViewer/DocumentViewerLoadingFile)
2. **Loading documents from data**
    
    In order to load a document from data, the DocumentDataproperty must retrieve a Base64 encoded string in the internal TX Text Control format. If you want to load a document from another format such as DOCX, the document must be converted first using the ServerTextControl. Typically, the document is loaded in the Controller and passed to the View as a Model.
    
    If a document is loaded from data, the DocumentPathproperty can contain a filename which is displayed in the status bar.
    
    ```
    @Html.TXTextControl().DocumentViewer(settings =>
    {
        settings.DocumentData = Convert.ToBase64String(
          File.ReadAllBytes(Server.MapPath("~/App_Data/Documents/car_insurance.tx")));
        settings.DocumentPath = "MyDocument.tx";
        settings.Dock = DocumentViewerSettings.DockStyle.Fill;
        settings.IsSelectionActivated = true;
        settings.ShowThumbnailPane = true;
    }).Render()
    ```
    
    [See this live ](https://demos.textcontrol.com/chapter/topic/DocumentViewer/DocumentViewerLoadingData)
3. **Loading documents from JavaScript**
    
    Documents can be loaded from client-side JavaScript as well. This is typically used when documents are asynchronously created server-side using MailMerge and then loaded into the DocumentViewer.
    
    This code shows how to load a document using Ajax from an HttpGet method of the Controller in order to load the results into the viewer.
    
    **View (HTML Helper)**
    
    ```
    @Html.TXTextControl().DocumentViewer(settings =>
    {
        settings.Dock = DocumentViewerSettings.DockStyle.Fill;
        settings.IsSelectionActivated = true;
        settings.ShowThumbnailPane = true;
    }).Render()
    
    <button onclick="LoadDocument('car_insurance.tx')" 
        class="btn mt-3 btn-success">Load Document</button>
    ```
    
    **Controller**
    
    ```
    [HttpGet]
    public string LoadDocument(string filename)
    {
        string sDocument = Convert.ToBase64String(
            System.IO.File.ReadAllBytes(
                Server.MapPath("~/App_Data/Documents/" + filename)));           
    
        return sDocument;
    }
    ```
    
    **View (JavaScript)**
    
    ```
    function LoadDocument(filename) {
         $('.alert').show();
    
        var bDocument;
        var serviceURL = "@Url.Action("LoadDocument", "TX")";
    
        // send document to controller
        $.ajax({
            type: "GET",
            url: serviceURL,
            data: {
                filename: filename
            },
            success: successFunc,
            error: errorFunc
        });
    }
    
    function successFunc(data, status) {
        TXDocumentViewer.loadDocument(data, "loaded.tx");
        TXDocumentViewer.toggleSidebar();
    
        $('.alert').hide();
    }
    
    function errorFunc() {
        alert("Error");
    }
    ```
    
    [See this live ](https://demos.textcontrol.com/chapter/topic/DocumentViewer/DocumentViewerLoadingFileJS)

---

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

- [Configuring ASP.NET and IIS for Larger Requests](https://www.textcontrol.com/blog/2019/12/20/documentviewer-configuring-aspnet-for-larger-requests/llms.txt)
- [Updated MVC DocumentViewer: Session-less and Improved Image Quality](https://www.textcontrol.com/blog/2019/12/12/updated-mvc-documentviewer-session-less-and-improved-image-quality/llms.txt)
- [Using Multiple Electronic Signatures on a Document](https://www.textcontrol.com/blog/2019/10/23/using-multiple-electronic-signatures/llms.txt)
- [MVC DocumentViewer Update: Printing, Resources and Mobile-Friendly Document Signing](https://www.textcontrol.com/blog/2019/10/18/mvc-documentviewer-update-printing-resources-mobile/llms.txt)
- [Using the ASP.NET MVC DocumentViewer JavaScript API](https://www.textcontrol.com/blog/2017/04/28/using-the-aspnet-mvc-documentviewer-javascript-api/llms.txt)
- [HTML5 Based MVC DocumentViewer Public Beta Program Launched](https://www.textcontrol.com/blog/2017/04/26/html5-based-mvc-documentviewer-public-beta-program-launched/llms.txt)
- [High-Performance Text Replacement in Large DOCX Files using C# .NET](https://www.textcontrol.com/blog/2025/07/30/high-performance-text-replacement-in-large-docx-files-using-csharp-dotnet/llms.txt)
- [Document Viewer 33.2.1 Released: New Event and Bug Fixes](https://www.textcontrol.com/blog/2025/07/30/document-viewer-33-2-1-released-new-event-and-bug-fixes/llms.txt)
- [Building an ASP.NET Core Backend (Linux and Windows) for the Document Editor and Viewer](https://www.textcontrol.com/blog/2025/03/26/building-an-asp-net-core-backend-for-the-document-editor-and-viewer/llms.txt)
- [TX Text Control Document Editor and Viewer for Blazor Released](https://www.textcontrol.com/blog/2025/03/25/tx-text-control-document-editor-and-viewer-for-blazor-released/llms.txt)
- [Getting Started: Document Viewer for Blazor in ASP.NET Core](https://www.textcontrol.com/blog/2025/03/25/getting-started-document-viewer-for-blazor-in-asp-net-core/llms.txt)
- [Announcing Our Work on a Blazor Component for Document Editing and Viewing](https://www.textcontrol.com/blog/2025/01/24/announcing-our-work-on-a-blazor-component-for-document-editing-and-viewing/llms.txt)
- [Preparing Documents for E-Signing for Multiple Signers in .NET C#](https://www.textcontrol.com/blog/2024/11/13/preparing-documents-for-e-signing-for-multiple-signers-in-net-c-sharp/llms.txt)
- [ASP.NET Core: Use the Document Editor and Viewer in the Same Razor View](https://www.textcontrol.com/blog/2024/11/08/asp-net-core-use-the-document-editor-and-viewer-in-the-same-razor-view/llms.txt)
- [Optimizing Digital Signature Workflows: Starting with MS Word DOCX Files Instead of PDFs in C#](https://www.textcontrol.com/blog/2024/09/27/optimizing-digital-signature-workflows-starting-with-ms-word-docx-files-instead-of-pdfs-in-csharp/llms.txt)
- [Document Viewer: Setting the Rendering Mode](https://www.textcontrol.com/blog/2024/08/22/document-viewer-setting-the-rendering-mode/llms.txt)
- [View MS Word DOCX and PDF Documents using a .NET C# Document Viewer for ASP.NET Core and ASP.NET](https://www.textcontrol.com/blog/2024/08/08/view-ms-word-docx-and-pdf-documents-using-a-net-csharp-document-viewer-for-aspnet-core-and-aspnet/llms.txt)
- [Stay Up-To-Date: Document Viewer 32.3.1 Released](https://www.textcontrol.com/blog/2024/08/08/stay-up-to-date-document-viewer-32-3-1-released/llms.txt)
- [Getting Started Video Tutorial: How to Add Electronic and Digital Signatures to PDF Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-add-electronic-and-digital-signatures-to-pdf-documents-in-asp-net-core-csharp/llms.txt)
- [Getting Started Video Tutorial: How to use the Document Viewer in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-use-the-document-viewer-in-asp-net-core-csharp/llms.txt)
- [Transforming Financial Documents into Smart and Secure Forms in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/05/01/transforming-financial-documents-into-smart-and-secure-forms-in-asp-net-core-c-sharp/llms.txt)
- [Document Viewer: Long Polling Support for Loading Documents](https://www.textcontrol.com/blog/2024/04/25/document-viewer-long-polling-support-for-loading-documents/llms.txt)
- [Adding and Sharing Annotations across Document Types using the Document Viewer in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/04/19/adding-and-sharing-annotations-across-document-types-using-the-document-viewer-in-asp-net-core-c-sharp/llms.txt)
- [Adding a Security Middleware to ASP.NET Core Web Applications to Protect TX Text Control Document Editor and Document Viewer Endpoints](https://www.textcontrol.com/blog/2024/03/18/adding-a-security-middleware-to-asp-net-core-web-applications-to-protect-tx-text-control-document-editor-and-document-viewer-endpoints/llms.txt)
- [Building an ASP.NET Core Backend Application to Host the Document Editor and Document Viewer](https://www.textcontrol.com/blog/2024/03/14/building-an-asp-net-core-backend-application-to-host-the-document-editor-and-document-viewer/llms.txt)
