Back to Devexpress

DxRichEdit.LoadDocumentAsync(Byte[], DocumentFormat, CancellationToken) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-dxrichedit-dot-loaddocumentasync-x28-system-dot-byte-devexpress-dot-blazor-dot-richedit-dot-documentformat-system-dot-threading-dot-cancellationtoken-x29.md

latest3.8 KB
Original Source

DxRichEdit.LoadDocumentAsync(Byte[], DocumentFormat, CancellationToken) Method

SECURITY-RELATED CONSIDERATIONS

The style-src: unsafe-inline CSP directive is not compatible with the LoadDocumentAsync method if called for documents using the HTML file format. Refer to the following help topic for additional information:

Content Security Policy (CSP).

Loads a document in the specified format from a byte array.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public ValueTask LoadDocumentAsync(
    byte[] bytes,
    DocumentFormat documentFormat,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

NameTypeDescription
bytesByte[]

A byte array that contains document data.

| | documentFormat | DocumentFormat |

Loaded document format.

|

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

Call the LoadDocumentAsync method to load a document (in the specified format) from a byte array.

The DocumentLoaded event occurs after the Rich Text Editor loads a document. Handle this event to change the content of a loaded document.

The following code snippet loads an RTF document from a byte array:

razor
<DxRichEdit @ref="@richEdit" />

@code {
    DxRichEdit richEdit { get; set; }
    @* ... *@
    /* 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 {
        @* ... *@
            byte[] fileContent = Convert.FromBase64String("e1xydGYxXGRlZmYwe1xmb250dGJse1xmMCBDYWxpYnJpO319e1xjb2xvcnRibCA7XHJlZDBcZ3JlZW4wXGJsdWUyNTUgO1xyZWQyNTVcZ3JlZW4yNTVcYmx1ZTI1NSA7fXtcKlxkZWZjaHAgXGZzMjJ9e1xzdHlsZXNoZWV0IHtccWxcZnMyMiBOb3JtYWw7fXtcKlxjczFcZnMyMiBEZWZhdWx0IFBhcmFncmFwaCBGb250O317XCpcY3MyXGZzMjJcY2YxIEh5cGVybGluazt9e1wqXHRzM1x0c3Jvd2RcZnMyMlxxbFx0c3ZlcnRhbHRcdHNjZWxsY2JwYXQyXHRzY2VsbHBjdDBcY2x0eGxydGIgTm9ybWFsIFRhYmxlO319e1wqXGxpc3RvdmVycmlkZXRhYmxlfXtcaW5mb31cbm91aWNvbXBhdFxzcGx5dHduaW5lXGh0bWF1dHNwXGV4cHNocnRuXHNwbHRwZ3BhclxkZWZ0YWI3MjBcc2VjdGRcbWFyZ2xzeG4xNDQwXG1hcmdyc3huMTQ0MFxtYXJndHN4bjE0NDBcbWFyZ2JzeG4xNDQwXGhlYWRlcnk3MjBcZm9vdGVyeTcyMFxwZ3dzeG4xMjI0MFxwZ2hzeG4xNTg0MFxjb2xzMVxjb2xzeDcyMFxwYXJkXHBsYWluXHFse1xmczIyXGNmMFxjczEgRG9jdW1lbnQgdGV4dH1cZnMyMlxjZjBccGFyfQ==");
            richEdit.LoadDocumentAsync(fileContent, DocumentFormat.Rtf);
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

See Also

Document Management in Blazor Rich Text Editor

DxRichEdit Class

DxRichEdit Members

DevExpress.Blazor.RichEdit Namespace