I am trying to persist some data from a rich text box to a BLOB in a database
void TestCode2()
{
TextRange range = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);
MemoryStream mem = new MemoryStream();
range.Save(mem, System.Windows.DataFormats.XamlPackage);
mem.Flush();
byte[] persist = mem.GetBuffer();
MemoryStream mem2 = new MemoryStream(persist);
try
{
range.Load(mem2, System.Windows.DataFormats.XamlPackage);
}
catch (ArgumentException ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Exception {0}", ex.Message));
}
}
The code above summarizes what I am trying to do.
But the main problem is an ArgumentException is being thrown.
But if do the following everything works OK: