This is a migrated thread and some comments may be shown as answers.

Insert content (rtf or html) into existing document

5 Answers 483 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Giereck
Top achievements
Rank 1
Giereck asked on 17 Nov 2011, 11:31 AM
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


5 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 21 Nov 2011, 09:43 AM
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 >>

0
Giereck
Top achievements
Rank 1
answered on 22 Nov 2011, 11:57 AM
Hi Boby,

Thank you for your reply!

How do I create a DocumentFragment from a RadDocument?

/Giereck
0
Iva Toteva
Telerik team
answered on 23 Nov 2011, 01:10 PM
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 >>

0
Michael Hilgers
Top achievements
Rank 1
answered on 05 Dec 2012, 12:07 PM
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?
0
Stefan
Telerik team
answered on 06 Dec 2012, 10:25 AM
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.

Tags
RichTextBox
Asked by
Giereck
Top achievements
Rank 1
Answers by
Boby
Telerik team
Giereck
Top achievements
Rank 1
Iva Toteva
Telerik team
Michael Hilgers
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or