Skip to main content

SubDocument.AddRtfAsync(Int32, String, CancellationToken) Method

Inserts text in Rich Text Format (RTF) into the sub-document at the specified position.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<Interval> AddRtfAsync(
    int position,
    string rtfText,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
position Int32

The target position in the sub-document for RTF text insertion.

rtfText String

The inserted RTF text string.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

An object that propagates a cancellation notification.

Returns

Type Description
ValueTask<Interval>

A structure that stores an awaitable result of an asynchronous operation. The awaitable result is the inserted interval.

Remarks

The following code snippet inserts the content of the C:\Temp\rtf-content.rtf file into a Rich Text Editor’s sub-document starting from the fifth character.

<DxRichEdit @ref="@richEdit" DocumentContent="@documentContent" CssClass="w-100 ch-720" />

@code {
    DxRichEdit richEdit { get; set; }
    Byte[] documentContent { get; set; }
    string rtfContent { get; set; }
    string pathInitial { get; set; } = @"C:\Temp\initial-content.docx";
    string pathRtf { get; set; } = @"C:\Temp\rtf-content.rtf";

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

    protected async override Task OnAfterRenderAsync(bool firstRender) {
        if (firstRender) {
            rtfContent = File.ReadAllText(pathRtf);
            await richEdit.DocumentAPI.AddRtfAsync(5, rtfContent);
        }
        await base.OnAfterRenderAsync(firstRender);
    }
}

To insert an RTF text string at the end of a sub-document, use the AddRtfAsync(String, CancellationToken) method.

See Also