Saving FlowDocument to SQL Server

后端 未结 3 950
春和景丽
春和景丽 2020-12-19 19:09

I need to save WPF FlowDocuments to SQL Server. What is the best format for doing that? String? Blob? Does it matter in a document less than 5K words or so?

3条回答
  •  再見小時候
    2020-12-19 19:16

    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 a Xaml string which can then be saved in 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);
    

提交回复
热议问题