Skip to main content

DxRichEdit.SaveDocumentAsync(CancellationToken) Method

Raises the DocumentContentChanged event.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask SaveDocumentAsync(
    CancellationToken cancellationToken = default(CancellationToken)
)

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

An object that propagates a cancellation notification.

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 following code snippet converts 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 canceled. */
        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}");
        }
    }
}

View Example: How to implement custom document save capabilities

See Also