blazor-devexpress-dot-blazor-dot-richedit-dot-subdocument-dot-addrtfasync-x28-system-dot-int32-system-dot-string-system-dot-threading-dot-cancellationtoken-x29.md
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
public ValueTask<Interval> AddRtfAsync(
int position,
string rtfText,
CancellationToken cancellationToken = default(CancellationToken)
)
| Name | Type | Description |
|---|---|---|
| position | Int32 |
The target position in the sub-document for RTF text insertion.
| | rtfText | String |
The inserted RTF text string.
|
| Name | Type | Default | Description |
|---|---|---|---|
| cancellationToken | CancellationToken | null |
An object that propagates a cancellation notification.
|
| Type | Description |
|---|---|
| ValueTask<Interval> |
A structure that stores an awaitable result of an asynchronous operation. The awaitable result is the inserted interval.
|
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
GetRtfAsync(Int32, Int32, CancellationToken)