Remove Hyperlinks when Executing PasteCommand?

2 posts, 0 answers
  1. Siamak
    Siamak avatar
    3 posts
    Member since:
    Sep 2012

    Posted 26 Oct 2012 Link to this post

    I try to do this by using this Thread's Posts but when I Paste Some text contain hyperlink in my RadRichTextBox , It shows the hyperlinks as usual way and doesn't remove Its styles and etc.
    I Want remove any styles, Images, Tables, Bullets, etc of document's content like when paste Clipboard in TextBox.
  2. Petya
    Petya avatar
    983 posts

    Posted 29 Oct 2012 Link to this post

    Hello Siamak,

    If I understand correctly, you wish to convert the rich text that has been copied and paste it as plain text.

    If this is the case, you can do so using the TxtFormatProvider which is built to import/export plain text.
    void radRichTextBox_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
        if (e.Command is PasteCommand)
            DocumentFragment fragment = ClipboardEx.GetDocument();
            if (fragment != null)
                TxtFormatProvider provider=new TxtFormatProvider();
                string plainText = provider.Export(fragment.ToDocument());
                this.radRichTextBox.InsertFragment(new DocumentFragment(provider.Import(plainText)));
                e.Cancel = true;
    This will strip the text in the clipboard of all formatting and will insert it at the caret position.

    I hope this helps.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top