Skip to main content
All docs
V24.1

SubDocument.GetHtmlAsync(Int32, Int32, CancellationToken) Method

Returns the specified interval’s content in HTML format. The interval is specified by its start position and length.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<string> GetHtmlAsync(
    int startPosition,
    int length,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
startPosition Int32

The interval’s start position.

length Int32

The interval’s length.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

An object that propagates a cancellation notification.

Returns

Type Description
ValueTask<String>

A structure that stores an awaitable result of an asynchronous operation. The awaitable result is an HTML text string.

Remarks

The following code snippet performs the following steps:

  1. Handles the DocumentLoaded event to access content of the loaded document.
  2. Calls the GetHtmlAsync method that obtains the first ten letters from the main sub-document and generates the corresponding HTML markup.
  3. Saves the obtained markup to the target-html.html file.
<DxRichEdit @ref="@richEdit"
            DocumentContent="@documentContent"
            DocumentLoaded="OnDocumentLoaded"/>

@code {
    DxRichEdit richEdit { get; set; }
    Byte[] documentContent { get; set; }
    string htmlContent { get; set; }
    string pathInitial { get; set; } = @"C:\Temp\initial.docx";
    string pathHtml { get; set; } = @"C:\Temp\target-html.html";

    protected override async Task OnInitializedAsync() {
        documentContent = await File.ReadAllBytesAsync(pathInitial);
        await base.OnInitializedAsync();
    }

    async Task OnDocumentLoaded(Document document) {
        try {
            var htmlContent = await document.GetHtmlAsync(0, 10);
            await File.WriteAllTextAsync(pathHtml, htmlContent);
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also