I am currently trying to figure out how to save the content from a RichTextbox into a stream(currently using FileStream) and do this alongside a bunch of other data. Then of course I want to be able to load from this file. I was currently trying to use something along the following lines.
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.
This is basically what I am trying to do. I am actually saving 2 TextRanges and a bunch more Properties. So my problem is that TextRange.Load() reads to the end of the file…making it impossible for me to use that considering I have 2 TextRanges I need to save/load. So here I am trying to come up with another way to be able to save/load the content of a RichTextBox with other data. I dont have to use a Stream. I am pretty much open to any feasible solutions. Thanks in advance!
~Jasson
You could load/save to a MemoryStream to solve your issue with reading to the end of the file. It could look like this:
Or are you wanting to know how you’d create and parse a file to contain different sections for the title, and the contents, and any other fields ?