Skip to main content
All docs
V24.2

SubDocument.GetHtmlAsync(Interval, CancellationToken) Method

Returns the specified interval’s content in HTML format.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<string> GetHtmlAsync(
    Interval interval,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
interval Interval

The interval that contains required content.

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 GetIntervalAsync(CancellationToken) method to access a sub-document’s interval. This interval corresponds to the main sub-document.
  3. Passes the returned interval to the GetHtmlAsync method to obtain the sub-document’s content as HTML markup.
  4. 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 {
            Interval interval = await document.GetIntervalAsync();
            var htmlContent = await document.GetHtmlAsync(interval);
            await File.WriteAllTextAsync(pathHtml, htmlContent);
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also