这里主要是将richtextbox中的内容转换成字节数组,主要是将字节流打包的过程:方法可用,已测试

命名空间

using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Xml;using System.Text;

1,转换为字节

private byte[] GetRichTextBox(RichTextBox box)
{
MemoryStream m=new MemoryStream();
TextRange documentRange=new TextRange(box.Document.ContentStart,box.Document.ContentEnd);
documentRange.Save(m,DataFormats.XamlPackage);
return m.ToArray();

}

2,字节转换为RichTextBox数据

Private void showRichTextBox(RichTextBox rt,byte[] bytes )
{
MemoryStream m=new MemoryStream (bytes);
TextRange documentRange=new TextRange(box.Document.ContentStart,box.Document.ContentEnd);
documentRange.Load(m,DataFormats.XamlPackage);
}