Saving FlowDocument to SQL Server

后端 未结 3 940
春和景丽
春和景丽 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:25

    You can serialize FlowDocument using the TextRange class. You can even use the RTF format. Saving:

    FlowDocument docToSave; // Lets suppose this var is initialized.
    var tr = new TextRange(docToSave.ContentStart,docToSave.ContentEnd);
    var dst = new MemoryStream();
    tr.Save(dst, DataFormats.Rtf);
    dst.Close();
    

    And loading:

    FlowDocument docToLoad = new FlowDocument();
    var tr = new TextRange(docToLoad.ContentStart,docToLoad.ContentEnd);
    Stream src; // Lets suppose it is initialized.
    tr.Load(src, DataFormats.Rtf);
    src.Close();
    

    See also https://www.wpf-tutorial.com/rich-text-controls/how-to-creating-a-rich-text-editor/

提交回复
热议问题