Skip to main content
A newer version of this page is available. .

DxRichEdit.DocumentContent Property

Document content in an OpenXml format.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.RichEdit.v21.1.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

[Parameter]
public byte[] DocumentContent { get; set; }

Property Value

Type Description
Byte[]

Document content in an OpenXml format.

Remarks

Use the DocumentContent property to bind the Rich Text Editor to an Office Open XML document (DOCX).

@using System.IO;
@* ... *@
    <DxRichEdit Id="richEdit" DocumentContent="@documentContent" ViewType="ViewType.Simple" ActiveRibbonTabIndex="6" CssClass="w-100 ch-720" />

    @code {
        byte[] documentContent;

        protected override async Task OnInitializedAsync() {
            documentContent = await File.ReadAllBytesAsync(Path.Combine(AppContext.BaseDirectory, "Data\\Documents\\AlbertEinstein.docx"));
            await base.OnInitializedAsync();
        }
    }

The Rich Text Editor updates the DocumentContent property value in the following cases:

  • An auto-save timeout expires.

  • A user selects the FileSave ribbon command.

  • A user presses CTRL+S.

Handle the DocumentContentChanged event to save changes.

<DxRichEdit @ref="richEdit" Id="richEdit" AutoSaveTimeout="TimeSpan.FromMinutes(2)"
DocumentContent="@documentContent" DocumentContentChanged="OnDocumentContentChanged" />

@code {
    DxRichEdit richEdit { get; set; }
    byte[] documentContent { get; set; }
    string filePath = "C:\\Users\\Public\\annual-report.docx";

    async Task OnDocumentContentChanged(byte[] content) {
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is cancelled. */
        try {
            documentContent = content;
            await richEdit.ExportDocumentAsync(filePath, DocumentFormat.OpenXml);
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

To open a file in another format, call a LoadDocumentAsync method. Note that in this case, the DocumentContent property is not in effect.

See Also