officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-paragraphcollection-dot-insert-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-x29.md
Inserts a new Paragraph at a specified position.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
Paragraph Insert(
DocumentPosition pos
)
Function Insert(
pos As DocumentPosition
) As Paragraph
| Name | Type | Description |
|---|---|---|
| pos | DocumentPosition |
A DocumentPosition object that specifies a position to insert a new paragraph.
|
| Type | Description |
|---|---|
| Paragraph |
A paragraph that follows the inserted paragraph.
|
The code sample below appends a paragraph and inserts a paragraph at the start of the second section:
using DevExpress.XtraRichEdit.API.Native;
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
wordProcessor.LoadDocument("FirstLook.docx");
Document document = wordProcessor.Document;
document.BeginUpdate();
//Append paragraph:
Paragraph appendedParagraph = document.Paragraphs.Append();
document.InsertText(appendedParagraph.Range.Start, "Appended paragraph");
//Insert paragraph at the start of the second section:
Paragraph paragraph = document.Paragraphs.Insert(document.Sections[1].Range.Start);
document.InsertText(document.Paragraphs[paragraph.Index - 1].Range.Start,
"Inserted paragraph");
document.EndUpdate();
}
Imports DevExpress.XtraRichEdit.API.Native
Using wordProcessor As New RichEditDocumentServer()
wordProcessor.LoadDocument("FirstLook.docx")
Dim document As Document = wordProcessor.Document
document.BeginUpdate()
'Append paragraph:
Dim appendedParagraph As Paragraph = document.Paragraphs.Append()
document.InsertText(appendedParagraph.Range.Start, "Appended paragraph")
'Insert paragraph at the start of the second section:
document.InsertText(document.Paragraphs[paragraph.Index - 1].Range.Start
"Inserted paragraph");
document.InsertText(paragraph.Range.Start, "Inserted paragraph")
document.EndUpdate()
End Using
The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert(DocumentPosition) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
word-document-api-examples/CS/CodeExamples/CommentsActions.cs#L128
// Insert a text to the comment.
commentDocument.Paragraphs.Insert(commentDocument.Range.Start);
commentDocument.InsertText(commentDocument.Range.Start, "some text");
winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Shapes.cs#L84
DocumentRange newRange = boxedDocument.AppendDocumentContent(document.Paragraphs[1].Range);
boxedDocument.Paragraphs.Insert(newRange.Start);
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/ShapesActions.cs#L93
DocumentRange newRange = boxedDocument.AppendDocumentContent(document.Paragraphs[1].Range);
boxedDocument.Paragraphs.Insert(newRange.Start);
// Insert an image form the main document into the text box.
word-document-api-examples/VB/CodeExamples/CommentsActions.vb#L106
' Insert a text to the comment.
commentDocument.Paragraphs.Insert(commentDocument.Range.Start)
commentDocument.InsertText(commentDocument.Range.Start, "some text")
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Shapes.vb#L76
Dim newRange As DevExpress.XtraRichEdit.API.Native.DocumentRange = boxedDocument.AppendDocumentContent(document.Paragraphs(CInt((1))).Range)
boxedDocument.Paragraphs.Insert(newRange.Start)
' Insert an image form the main document into the text box.
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/ShapesActions.vb#L83
Dim newRange As DocumentRange = boxedDocument.AppendDocumentContent(document.Paragraphs(1).Range)
boxedDocument.Paragraphs.Insert(newRange.Start)
' Insert an image form the main document into the text box.
See Also