Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save and retrieve RichTextBox.Document from/to SQL?

I want to use a Wpf RichTextBox to edit data and resave it to SQL field. I need of course the text to be saved as rich text, not just simple text of course.

  1. What data-type should be best for storing in SQL server (2005 - forget about file stream)?
  2. How do I save/retrieve it?
like image 689
Shimmy Weitzhandler Avatar asked Aug 23 '09 13:08

Shimmy Weitzhandler


1 Answers

You can save the document to a XAML string using XamlWriter :

        StringWriter wr = new StringWriter();
        XamlWriter.Save(richTextBox.Document, wr);
        string xaml = wr.ToString();

You can then save the XAML string to a the database like any other text.

To reload it from a XAML string, use XamlReader :

        FlowDocument doc = XamlReader.Parse(xaml) as  FlowDocument;
like image 67
Thomas Levesque Avatar answered Sep 22 '22 23:09

Thomas Levesque