【发布时间】:2009-03-27 05:32:34
【问题描述】:
我目前正试图弄清楚如何将 RichTextbox 中的内容保存到流中(当前使用 FileStream),并与一堆其他数据一起执行此操作。然后我当然希望能够从这个文件中加载。 我目前正在尝试使用以下内容。
FileStream stream = new FileStream(); //this is actually correctly defined.
ASCIIEncoding encoding = new ASCIIEncoding();
//write Title
byte[] array = encoding.GetBytes(Title);
stream.WriteByte(Convert.ToByte(array.Length));
stream.Write(array, 0, array.Length);
//save textRange
textRange.Save(stream, System.Windows.DataFormats.Rtf);
//write Subtitle
byte[] array = encoding.GetBytes(Subtitle);
stream.WriteByte(Convert.ToByte(array.Length));
stream.Write(array, 0, array.Length);
//ect...and something very similar for Loading a file.
这基本上就是我想要做的。我实际上保存了 2 个 TextRanges 和更多的属性。所以我的问题是 TextRange.Load() 读取到文件的末尾......考虑到我有 2 个需要保存/加载的 TextRanges,我无法使用它。 所以在这里我试图想出另一种方法来保存/加载 RichTextBox 的内容和其他数据。我不必使用流。我对任何可行的解决方案都持开放态度。提前致谢!
~杰森
【问题讨论】:
标签: c# load richtextbox save