日期:2014-05-17 浏览次数:20823 次
TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
using (MemoryStream ms = new MemoryStream())
{
textRange.Save(ms, System.Windows.DataFormats.Rtf);
ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms);
var rtf = sr.ReadToEnd();
File.WriteAllText("rtfsample.rtf", rtf);
}
var fs = new FileStream("rtfsample.rtf", FileMode.Open, FileAccess.Read);
StreamReader streamReader = new StreamReader(fs, System.Text.Encoding.UTF8);
using (fs)
{
TextRange text = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
text.Load(fs, DataFormats.Rtf);
}
streamReader.Dispose();
streamReader = null;
fs.Dispose();
fs = null;