How do I insert another document at a bookmark

2 posts, 0 answers
  1. Edward
    Edward avatar
    84 posts
    Member since:
    Feb 2011

    Posted 21 Jun 2012 Link to this post

    So I have 2 document, one with a bookmark.

    I want to insert document B into document A at a that bookmark.  Is that possible to achieve?
  2. Iva Toteva
    Iva Toteva avatar
    1319 posts

    Posted 22 Jun 2012 Link to this post

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

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

Back to Top