Back to Devexpress

SubDocument.AddRtfAsync(Int32, String, CancellationToken) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-subdocument-dot-addrtfasync-x28-system-dot-int32-system-dot-string-system-dot-threading-dot-cancellationtoken-x29.md

latest3.3 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

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

Parameters

NameTypeDescription
positionInt32

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

| | rtfText | String |

The inserted RTF text string.

|

Optional Parameters

NameTypeDefaultDescription
cancellationTokenCancellationTokennull

An object that propagates a cancellation notification.

|

Returns

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

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

GetRtfAsync(Int32, Int32, CancellationToken)

GetRtfAsync(Interval, CancellationToken)

SubDocument Class

SubDocument Members

DevExpress.Blazor.RichEdit Namespace