views:

472

answers:

2

Hello all.

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?
+1  A: 

The datatype in SQL should probably be NVARCHAR(MAX): Nvarchar means you can store unicode, and MAX means you can store unlimited amounts, (well up to 2GB anyway) of data.

edosoft
Would you recoment to save it varbinary?
Shimmy
varbinary is typicaly for images, or other byte streams.
edosoft
What is better for performance?I am not sure if images will be needed.But if varbinary's performance usage <= varchar, than I prefer varchar, cuz I want to make it harded to read the sql raw data.The thing is I donno how to exrecat/load the FlowDocument from byte[]
Shimmy
+1  A: 

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;
Thomas Levesque