Back to Devexpress

DxRichEdit.SaveDocumentAsync(CancellationToken) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-dxrichedit-dot-savedocumentasync-x28-system-dot-threading-dot-cancellationtoken-x29.md

latest3.9 KB
Original Source

DxRichEdit.SaveDocumentAsync(CancellationToken) Method

Raises the DocumentContentChanged event.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

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

Optional Parameters

NameTypeDefaultDescription
cancellationTokenCancellationTokennull

An object that propagates a cancellation notification.

|

Returns

TypeDescription
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:

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

Document Management in Blazor Rich Text Editor

DxRichEdit Class

DxRichEdit Members

DevExpress.Blazor.RichEdit Namespace