# docx-editor-auto-save

> Document editor that automatically saves document changes through a configurable server endpoint.

**Framework:** aspnet-mvc  **Component:** DocxEditor  **Variant:** auto-save

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-mvc/docx-editor-auto-save.json
```

**Install Package(s)**

```bash
Install-Package Syncfusion.AspNetMvc.DocumentEditor
Install-Package Syncfusion.AspNetMvc.Buttons
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/docx-editor-auto-save/DocxEditor.cshtml

```cshtml
@using Syncfusion.EJ2
@section ControlsSection{
    <div class="col-lg-9 control-section">
        <div class="flex-container">
            <label class="switchLabel" for="checked">Ribbon UI</label>
            @*<div class="e-message render-mode-info">
                    <span class="e-msg-icon render-mode-info-icon" title="Turn OFF to switch from Ribbon to toolbar UI"></span>
                </div>
                @Html.EJS().Switch("toolbarSwitch").CssClass("buttonSwitch").Change("onSwitchChange").Checked(true).Render()*@
        </div>
        <div id='documenteditor_titlebar' class="e-de-ctn-title"></div>
        @Html.EJS().DocumentEditorContainer("container").Height("590px").EnableToolbar(true).Render()
    </div>
    <div class="col-lg-3 property-section">
        <table id="property" title="Auto save log">
            <tr>
                <td>
                    <div class="eventarea" style="height: 245px;overflow: auto">
                        <span class="AutosaveLog" id="AutosaveLog" style="word-break: normal;"></span>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="evtbtn" style="padding-bottom: 10px">
                        @Html.EJS().Button("log_clear").Content("Clear").IsPrimary(false).Render()
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <script src="~/Scripts/documenteditor/default-properties.js"></script>
}

@section Scripts{
    <script>
    var contentChanged = false;
    var documenteditor;
    ej.documenteditor.DocumentEditorContainer.Inject(ej.documenteditor.Toolbar, ej.documenteditor.Ribbon);

document.addEventListener('DOMContentLoaded', function () {
        var documenteditorElement = document.getElementById("container");
        documenteditorElement.style.height = "590px";
        documenteditorElement.style.width = "100%";
        var container = documenteditorElement.ej2_instances[0];
            container.toolbarMode = "Ribbon";
        container.showPropertiesPane = true;
        container.documentEditorSettings.showRuler = true;
        documenteditor = container.documentEditor;
        documenteditorElement.ej2_instances[0].serviceUrl = window.baseurl + 'api/documenteditorservice/';
        documenteditor.serviceUrl = window.baseurl + 'api/documenteditorservice/';
        var ajax = new ej.base.Ajax("@Url.Content("~/scripts/documenteditor/data-default.json")", 'GET', true);
        ajax.send().then();
        ajax.onSuccess = function (data) {
            documenteditor.open(data);
            documenteditor.documentName = 'Auto Save';
            updateDocumentTitle();
        };
        titleBarDiv = document.getElementById('documenteditor_titlebar');
        initComponentAndWireEvent();
        showButtons(false);
        var exportItem = {
            text: 'Export',
            id: 'custom_item',
            iconCss: 'e-icons e-export',
            items: [
                { id: 'sfdt', text: 'Syncfusion Document Text (*.sfdt)' },
                { id: 'docx', text: 'Word Document (*.docx)' },
                { id: 'dotx', text: 'Word Template (*.dotx)' },
                { id: 'text', text: 'Plain Text (*.txt)' },
                { id: 'pdf', text: 'PDF (*.pdf)' },
                { id: 'html', text: 'HyperText Markup Language (*.html)' },
                { id: 'rtf', text: 'Rich Text Format (*.rtf)' },
                { id: 'md', text: 'Markdown (*.md)' },
                { id: 'odt', text: 'OpenDocument Text (*.odt)' },
                { id: 'wordml', text: 'Word XML Document (*.xml)' },
            ],
        };
        container.fileMenuItems = ['New', 'Open', exportItem, 'Print'];
        container.fileMenuItemClick = function (args) {
            if (args.item.id) {
                var value = args.item.id;
                var sampleName = container.documentEditor.documentName === '' ? 'sample' : container.documentEditor.documentName;
                switch (value) {
                    case 'docx':
                        container.documentEditor.save(sampleName, 'Docx');
                        break;
                    case 'sfdt':
                        container.documentEditor.save(sampleName, 'Sfdt');
                        break;
                    case 'text':
                        container.documentEditor.save(sampleName, 'Txt');
                        break;
                    case 'dotx':
                        container.documentEditor.save(sampleName, 'Dotx');
                        break;
                    case 'pdf':
                        saveFormat('Pdf');
                        break;
                    case 'html':
                        saveFormat('Html');
                        break;
                    case 'odt':
                        saveFormat('Odt');
                        break;
                    case 'md':
                        saveFormat('Md');
                        break;
                    case 'rtf':
                        saveFormat('Rtf');
                        break;
                    case 'wordml':
                        saveFormat('Xml');
                        break;
                }
            }
        };
        container.dataBind();

        container.documentChange = function () {
            updateDocumentTitle();
            documenteditor.focusIn();
        };

        container.contentChange = function() {
            contentChanged = true;
        };

        setInterval(() => {
            if (contentChanged) {
                //You can save the document as below
                container.documentEditor.saveAsBlob('Docx').then((blob) => {
                    var exportedDocumment = blob;
                    //Now, save the document where ever you want.
                    /* tslint:disable */
                    var span = document.createElement('span');
                    var date = new Date();
                    var time = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
                    span.innerHTML = 'Auto saved at <b>' + time + '</b><hr>';
                    var log = document.getElementById('AutosaveLog');
                    log.insertBefore(span, log.firstChild);
                });
                contentChanged = false;
            }
        }, 15000);

        document.getElementById("log_clear").addEventListener('click', function () {
            document.getElementById('AutosaveLog').innerHTML = '';
        });
    });

    function saveFormat(type) {
        var spinTarget = document.getElementById('container');
        ej.popups.createSpinner({
            target: spinTarget
        });
        ej.popups.showSpinner(spinTarget);
        var container = document.getElementById("container").ej2_instances[0];
        var format = type;
        var url = window.baseurl + 'api/documenteditorservice/Export';
        var http = new XMLHttpRequest();
        http.open('POST', url);
        http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
        var sfdt = {
            Content: container.documentEditor.serialize(),
            Filename: container.documentEditor.documentName,
            Format: '.' + format
        };
        http.onload = function () {
            if (http.status === 200) {
                var responseData = http.response;
                var downloadLink = document.createElement('a');
                downloadLink.href = responseData;
                downloadLink.download = container.documentEditor.documentName + '.' + (format).toLowerCase();
                document.body.appendChild(downloadLink);
                ej.popups.hideSpinner(spinTarget);
                downloadLink.click();
                document.body.removeChild(downloadLink);
            }
            else {
                console.error('Request failed with status:', http.status);
                ej.popups.hideSpinner(spinTarget);
            }
        };
        http.send(JSON.stringify(sfdt));
    }
    </script>
}

<style>
    #container {
        display: block;
        height: 500px;
    }

    .flex-container {
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }

    .render-mode-info {
        background: none;
        border: none;
        padding-left: 0px;
    }

        .render-mode-info .render-mode-info-icon {
            height: 16px;
            width: 16px;
        }

    .switchLabel {
        font-family: "Segoe UI", "GeezaPro", "DejaVu Serif", sans-serif;
        font-weight: 400;
        line-height: 20px;
        letter-spacing: 0.24px;
        text-align: right;
        font-size: 14px;
        margin-bottom: 0px;
    }

    .render-mode-info .render-mode-info-icon::before {
        line-height: normal;
    }

    .buttonSwitch {
        Width: 40px;
        Height: 24px;
    }

    #documenteditor_titlebar {
        border-bottom: 1px solid #2B3481;
        height: 36px;
        line-height: 26px;
        width: 100%;
        font-size: 12px;
        padding-left: 15px;
        padding-right: 10px;
        font-family: inherit;
    }

    #documenteditor_title_contentEditor {
        height: 26px;
        max-width: 85%;
        width: auto;
        overflow: hidden;
        display: inline-block;
        padding-left: 4px;
        padding-right: 4px;
        margin: 5px;
    }

    .single-line {
        cursor: text !important;
        outline: none;
    }

        .single-line:hover {
            border-color: #e4e4e4 !important;
        }

    [contenteditable="true"].single-line {
        white-space: nowrap;
        border-color: #e4e4e4 !important;
    }

    #AutosaveLog b {
        color: #388e3c;
    }

    /** Document editor sample level font icons*/

    @@font-face {
        font-family: 'Sample brower icons';
        font-weight: normal;
        font-style: normal;
    }

    [class^="e-de-icon-"],
    [class*=" e-de-icon-"] {
        font-family: 'Sample brower icons' !important;
    }

    .e-de-icon-Print:before {
        content: "\e723";
    }

    .e-de-icon-Download:before {
        content: "\e728";
    }

    /** sample level font icons ends*/
</style>
```

### src/components/docx-editor-auto-save/DocxEditorController.cs

```cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EJ2MVCSampleBrowser.Controllers.DocumentEditor
{
    public partial class DocumentEditorController : Controller
    {
        // GET: AutoSave
        public ActionResult AutoSave()
        {
            this.DocumentEditorViewResultHelper();
            return View("~/Views/Home/docx-editor/auto-save/DocxEditor.cshtml");
        }
    }
}
```
