1

我在控制台应用程序中遇到异常

HResult -2146233033 InnerException  null 
Message File contains corrupted data. 
Source  WindowsBase SourceUri   null StackTrace    at MS.Internal.IO.Zip.ZipIOEndOfCentralDirectoryBlock.FindPosition(Stream archiveStream)    at MS.Internal.IO.Zip.ZipIOEndOfCentralDirectoryBlock.SeekableLoad(ZipIOBlockManager blockManager)    at MS.Internal.IO.Zip.ZipArchive..ctor(Stream archiveStream, FileMode mode, FileAccess access, Boolean streaming, Boolean ownStream)    at MS.Internal.IO.Zip.ZipArchive.OpenOnStream(Stream stream, FileMode mode, FileAccess access, Boolean streaming)    at System.IO.Packaging.ZipPackage..ctor(Stream s, FileMode mode, FileAccess access, Boolean streaming)    at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming)  

试过这个寻找答案,但它没有帮助。

string xpsfilename = @"D:\test\sample_file.xps";

var webClient = new System.Net.WebClient();

var data = webClient.DownloadData(xpsfilename);
//var data = File.ReadAllBytes(xpsfilename);
using (MemoryStream stream = new System.IO.MemoryStream(data))
{
    var package = System.IO.Packaging.Package.Open(stream); /* Exception thrown here */
    var xpsDocument = new System.Windows.Xps.Packaging.XpsDocument(package, System.IO.Packaging.CompressionOption.SuperFast, xpsfilename);
    var sequence = xpsDocument.GetFixedDocumentSequence();

    SaveDocumentPagesToImages(sequence, @"D:\test");
}
4

0 回答 0