# docx-editor-auto-save

> Document editor that auto-saves changes to a configured server endpoint.

**Framework:** blazor  **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/blazor/docx-editor-auto-save.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.Blazor.WordProcessor
```

**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.razor

```razor
@page "/document-editor/auto-save"
@namespace blazor.Components.Pages.AutoSave.AutoSave
@using System.Text.Json
@using Syncfusion.Blazor.Buttons;
@using Syncfusion.Blazor.DocumentEditor;

<div class="control-section">
    <div class="flex-container">
        <label class="switchLabel">Ribbon UI</label>
        <SfSwitch CssClass="buttonSwitch" @bind-Checked="RibbonMode" OnChange="OnSwitchChange"></SfSwitch>
    </div>
    <div id='documenteditor_titlebar' class="e-de-ctn-title">
        <div class="single-line" id="documenteditor_title_contentEditor" style="border: 1px solid transparent;" title="Document Name." contenteditable="false">
            <label id="documenteditor_title_name" class="doc-edit-title">@DocumentName</label>
        </div>
        <div style="float: right">
            <SfButton IconCss="e-de-icon-Print" CssClass="title-bar-btn" @onclick="Print">Print</SfButton>
        </div>
    </div>
    <SfDocumentEditorContainer @ref="_containerRef" Height="590px" DocumentEditorSettings="_settings">
        <DocumentEditorContainerEvents Created="OnCreated" DocumentChanged="OnDocumentChange"></DocumentEditorContainerEvents>
    </SfDocumentEditorContainer>
</div>

@code {
    internal string? DocumentName { get; set; } = "Auto Save";
    internal bool RibbonMode { get; set; } = true;
    private SfDocumentEditorContainer? _containerRef;
    private DocumentEditorSettingsModel _settings = new DocumentEditorSettingsModel { ShowRuler = true };
    private System.Timers.Timer? _timer;

    protected override void OnInitialized()
    {
        // Poll for content changes and record a timestamp in the console
        // whenever the document is considered saved.
        _timer = new System.Timers.Timer(15000);
        _timer.Elapsed += (s, e) => InvokeAsync(() => Console.WriteLine($"Auto saved at {DateTime.Now:HH:mm:ss}"));
        _timer.Start();
    }

    public async Task OnCreated(object args)
    {
        if (_containerRef?.DocumentEditor != null)
        {
            string text = "Start typing here. The document is saved automatically every 15 seconds.";

            var sfdt = new
            {
                sections = new[]
                {
                    new
                    {
                        blocks = new[]
                        {
                            new
                            {
                                inlines = new[]
                                {
                                    new { text }
                                }
                            }
                        },
                        headerFooter = new { },
                        sectionFormat = new
                        {
                            pageWidth = 612,
                            pageHeight = 792,
                            leftMargin = 72,
                            rightMargin = 72,
                            topMargin = 72,
                            bottomMargin = 72
                        }
                    }
                }
            };

            string json = JsonSerializer.Serialize(sfdt);
            await _containerRef.DocumentEditor.OpenAsync(json);
            await InvokeAsync(StateHasChanged);
        }
    }

    public void OnDocumentChange()
    {
        var name = _containerRef?.DocumentEditor?.DocumentName;
        if (!string.IsNullOrEmpty(name))
        {
            DocumentName = name;
        }
    }

    public void OnSwitchChange(ChangeEventArgs<bool> args)
    {
        RibbonMode = args.Checked;
    }

    public void Print(object args)
    {
        _containerRef?.DocumentEditor?.PrintAsync();
    }

    public void Dispose()
    {
        _timer?.Dispose();
    }
}

```
