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

Loading RTF file with images to FlowDocument in console application

$
0
0

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);
    }

}
If I do this in WPF application and show the document in flowDocumentPageViewer, everythink is OK. But if I try to load file in console application, I get exception: Unrecognized structure in data format Rich Text Box, parameter name stream.

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


Viewing all articles
Browse latest Browse all 18858

Trending Articles



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