Saving FlowDocument in SQL Server

I need to save WPF FlowDocuments on SQL Server. What is the best format for this? Line? Blob? Does the document matter less than 5 thousand words or so?

+4
source share
2 answers

If you want to just save the FlowDocument objects to the database without any processing, I would recommend using binary serialization and storing the resulting byte array in varbinary (max). It scales quickly and well.

However, if you already have XML FlowDocuments files, it would be easier to drop them into the nvarchar (max) field without additional (added) serialization / deserialization. This scales trivially for values โ€‹โ€‹below 8k, and then looks OK until you click the 10 MB mark.

+5
source

FlowDocument is not serializable, so SWeko's answer above will not work. You can use the methods below to get the FlowDocument to and from the Xaml string, which can then be saved to the database using nvarchar (max).

var stringReader = new StringReader(info); var xmlTextReader = new XmlTextReader(stringReader); return (FlowDocument)XamlReader.Load(xmlTextReader); 

and

  var infoString = XamlWriter.Save(info); 
+4
source

Source: https://habr.com/ru/post/1304155/


All Articles