【发布时间】:2018-01-09 07:50:30
【问题描述】:
我有一个存储在 sql server 中的 xps 文件内容的字节数组,我正在尝试检索它并将其显示到 DocumentViewer 控件中。
cmd.CommandText = "select text from [table] where docName = '" + selectedText + "'";
using (SqlDataReader read = cmd.ExecuteReader())
{
while (read.Read())
{
byte[] retrieve = ((byte[])read["text"]); //text is column name for the byte array
var package = System.IO.Packaging.Package.Open(new MemoryStream(retrieve));
var xpsDocument = new XpsDocument(package, System.IO.Packaging.CompressionOption.Maximum);
pptViewer.Visibility = System.Windows.Visibility.Visible;
pptViewer.Document = xpsDocument.GetFixedDocumentSequence();
}
}
问题是这一行new XpsDocument(package, System.IO.Packaging.CompressionOption.Maximum) 需要一个额外的参数——文件的Uri。我没有它,因为它没有存储在本地 - 我将它转换为字节数组然后存储它,所以原来的 xps 文件不见了。
是否可以将字节数组转换为没有任何 uri 的 xps 文档?如果没有,我还能如何在我的 wpf 应用程序中显示文档(来自一个字节数组,当然)?
【问题讨论】:
-
File.WriteAllBytes(string path, byte[] bytes) 用正确的扩展名可以吗?