Skip to main content
All docs
V21.2

DxRichEdit.SaveDocumentAsync() Method

Raises the DocumentContentChanged event.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask SaveDocumentAsync()

Returns

Type Description
ValueTask

A structure that stores an awaitable result of an asynchronous operation.

Remarks

The SaveDocumentAsync method raises the DocumentContentChanged event when one of the following conditions is met:

The DocumentFormat property specifies a format in which the DocumentContent property stores content of an open document. Change the DocumentFormat property value and call the SaveDocumentAsync method to convert the document to another format and update the DocumentContent property value.

The example below demonstrates how to convert a document to another format and save the document to a file:

<DxRichEdit @ref="@richEdit" DocumentContent="@documentContent" DocumentFormat="@format"
    DocumentContentChanged="OnDocumentContentChanged" />

@code {
    byte[] documentContent;
    DxRichEdit richEdit;
    DocumentFormat format = DocumentFormat.Rtf;

    protected override async Task OnInitializedAsync() {
    /* 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 = await File.ReadAllBytesAsync("C:\\Users\\Public\\annual-report.rtf");
            format = DocumentFormat.OpenXml;
            await richEdit.SaveDocumentAsync();
            await base.OnInitializedAsync();
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }

    async Task OnDocumentContentChanged(byte[] content) {
        try {
            documentContent = content;
            await File.WriteAllBytesAsync("C:\\Users\\Public\\annual-report.docx", documentContent);
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also