Insert content (rtf or html) into existing document

6 posts, 0 answers
  1. Giereck
    Giereck avatar
    5 posts
    Member since:
    Oct 2009

    Posted 17 Nov 2011 Link to this post

    Hi,

    Im trying to use RadRichTextBox together with the Ribbon control to get a Word-like text editor in my application.

    So far I've initialized the editor with some content, which can be either plain text, RTF of HTML, so I used the different format providers and its working like a charm.

    Now I want to be able to insert content at the caret position. For inserting plain text, I'm using the Insert method, and its working fine, but how do I insert RTF and HTML? On top of that, the inserted RTF or HTML should keep its original formatting and style.

    /giereck


  2. Boby
    Admin
    Boby avatar
    595 posts

    Posted 21 Nov 2011 Link to this post

    Hi Giereck,
    You can use RadRichTextBox.InsertFragment method. DocumentFragment itself could be created from an instance of RadDocument, created from RtfFormatProvider or HtmlFormatProvider, depending on the format you want to import.

    Don't hesitate to contact us if you have other questions.

    Regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Giereck
    Giereck avatar
    5 posts
    Member since:
    Oct 2009

    Posted 22 Nov 2011 Link to this post

    Hi Boby,

    Thank you for your reply!

    How do I create a DocumentFragment from a RadDocument?

    /Giereck
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 23 Nov 2011 Link to this post

    Hi Giereck,

    In the versions starting from Q2 SP1 (2011.2.920), you can create a DocumentFragment like this:

    DocumentFragment fragment = new DocumentFragment(document);
    this.editor.InsertFragment(fragment); //Insert the fragment at caret position
    Before that, a document fragment could only be created through selection:
    document.Selection.SelectAll();
    DocumentFragment fragment = document.Selection.CopySelectedDocumentElements();

    Greetings,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Michael Hilgers
    Michael Hilgers avatar
    76 posts
    Member since:
    Apr 2010

    Posted 05 Dec 2012 Link to this post

    Hello Everyone,

    is this no longer valid?
    DocumentFragment fragment = new DocumentFragment(document);

    For me with Q3 2012 it says that there is no constructor taking 1 argument. But there aren't any constructores!

    How can i create a DocumentFragment now??

    Best Regards,
    Michael

    P.S.: I'm on WinForms, not on WPF, but it this a difference?
  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 06 Dec 2012 Link to this post

    Hi Michael,

    Thank you for writing.

    Yes there is a difference, so please address your question in the WinForms forums: http://www.telerik.com/community/forums/winforms/richtextbox.aspx, where our colleagues will assist you.

    Kind regards,
    Stefan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready