Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Exception when i try to get text from WPF RichTextBox

$
0
0
I get a NotSupported exception on tr.Save below: 
Exception thrown: 'System.NotSupportedException' in PresentationCore.dll
Additional information: BitmapMetadata is not available on BitmapImage.

This happens if i copy and paste text and a pic from a word docx to the richtextbox 
(named rtbEditor in the code below) and then try to retrieve the text 
with the code below. This so far seems to bve a 'friendly' error in that code execution 
continues, and if i store that rtf string, get it again, and send it to the richtextbox
, the image does display. I'll also mention that it is a wpf richtextbox used in a winforms app,
in case that matters. All that said, i'd really  like to avoid 'friendly' errors, because they make 
debugging real errors more difficult than necessary. TIA for any help :]

public string Rtf
{
get
{
TextRange tr = new TextRange(rtbEditor.Document.ContentStart, rtbEditor.Document.ContentEnd);
                string stext = null;
                using (MemoryStream ms = new MemoryStream())
                {
                    tr.Save(ms, DataFormats.Rtf);
                    stext = ASCIIEncoding.Default.GetString(ms.ToArray());
                }

                return stext;
}

}







Viewing all articles
Browse latest Browse all 18858


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>