I am creating simple console application where I need to load RTF file to FlowDocument for further work.
I am using this code for loading file to FlowDocument:
// Create OpenFileDialog Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();// Set filter for file extension and default file extension dlg.DefaultExt = ".rtf"; dlg.Filter = "RichText Files (*.rtf)|*.rtf";// Display OpenFileDialog by calling ShowDialog method Nullable<bool> result = dlg.ShowDialog();if (result == true) {// Open document string filename = dlg.FileName; FlowDocument flowDocument = new FlowDocument(); TextRange textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);using (FileStream fileStream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { textRange.Load(fileStream, DataFormats.Rtf); } }
And for some reason, this exception appears only, if there is image in document.
Any ideas whats wrong or better how to solve it?
Thanks for reply, Vebloud