I want to insert document B into document A at a that bookmark. Is that possible to achieve?
1 Answer, 1 is accepted
0
Iva Toteva
Telerik team
answered on 22 Jun 2012, 11:26 AM
Hello Edward,
Yes, this is possible to achieve this scenario.
In general, you can create instances of DocumentFragment in on of these two ways:
1. Using the constructor of DocumentFragment:
DocumentFragment fragment = new DocumentFragment(document);
If you create the fragment in this way, it will end with a new paragraph. This is convenient when you want to separate the inserted fragment and end it with a new line. Furthermore, in this way if the last paragraph is in a list, it will appear properly in the new document.
2. Using the selection:
document.Selection.SelectAll();
DocumentFragment fragment = document.Selection.CopySelectedDocumentElements();
In this way, and additional new line will not be added to the document.
Whichever way you choose to create the fragment, you can insert it at the current caret position using the InsertFragment method. In your case, you should first move the caret position to the bookmark as follows:
mainDocument.GoToBookmark(bookmarkName);
mainDocument.InsertFragment(fragment);
In case you have loaded the main document in the editor, you can use the InsertFragment method of RadRichTextBox to insert the fragment. This will preserve the undo/redo history.
I hope this answers your question.
All the best,
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>