read html from editor

3 posts, 1 answers
  1. Roman
    Roman avatar
    19 posts
    Member since:
    Apr 2019

    Posted 18 Nov 2019 Link to this post

    Hi there,

    I'm using the RadRichTextEditor the first time and I'm wondering if it is somehow possible to get only the HTML out of the editor. I've thought about something like:

    1.string htmlText = txtText.Text; // while txtText is my RadRichTextEditor


    But this returns me the plain text, without any html tags. I've seen I can export and import it using a HtmlFormatProvider. This worked great, but it is not exactly the thing I want, since it returns the whole HTML document instead of only the html I have in my text editor.

    1.HtmlFormatProvider prov = new HtmlFormatProvider();
    2.string htmlText = prov.Export(txtText.Document);

    The output I wish would be something like this:

    1.string htmlText = "This is a <b>bold</b> text. Great, isn't it?"

    Regards,
    Roman
  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2951 posts

    Posted 19 Nov 2019 Link to this post

    Hi Roman, 

    You can configure this in the export settings. For example, you can set the following properties: 

    HtmlFormatProvider provider = new HtmlFormatProvider();
    provider.ExportSettings.DocumentExportLevel = DocumentExportLevel.Fragment;
    provider.ExportSettings.StylesExportMode = StylesExportMode.Inline;
    provider.ExportSettings.StyleRepositoryExportMode = StyleRepositoryExportMode.DontExportStyles;
    
    string result = provider.Export(radRichTextEditor1.Document);
    

    Detailed information is available here: Settings | RadRichTextEditor.

    I hope this helps. Please let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Roman
    Roman avatar
    19 posts
    Member since:
    Apr 2019

    Posted 19 Nov 2019 in reply to Dimitar Link to this post

    Hi Dimitar,

    Great! This is exactly what I need. Thanks for the answer.

    Regards,
    Roman
Back to Top