I am saving a WPF FlowDocument to the file system, using this code and a fileName with an xps extension:
// Save FlowDocument to file system as XPS document
using (var fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
var textRange = new TextRange(m_Text.ContentStart, m_Text.ContentEnd);
textRange.Save(fs, DataFormats.XamlPackage);
}
My app can reload the document using this code:
// Load file
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
m_Text = new FlowDocument();
var textRange = new TextRange(m_Text.ContentStart, m_Text.ContentEnd);
textRange.Load(fs, DataFormats.XamlPackage);
}
However, the XPS Viewer that ships with Windows 7 can't open the files. The saved XPS files display the XPS icon, but when I double click one, the XPS viewer fails to open it. The error message reads "The XPS Viewer cannot open this document."
Any idea what I need to do to my XPS document to make it openable by the XPS Viewer? Thanks for your help.