简体   繁体   English

使用.Net 4.5 ZipFile,无法解压缩使用Windows zip压缩的文件(右键单击发送到Compressed)

[英]Using .Net 4.5 ZipFile, cannot unzip a file zipped with Windows zip (right click send to Compressed)

Am implementing a feature in an ASP.NET web application in the office to let people upload zip files in which there is an xml file to import into a database. 我正在办公室的ASP.NET Web应用程序中实现一项功能,使人们可以上载zip文件(其中有一个xml文件要导入数据库)。

The problem is, I get this error when using System.IO.Compression.ZipFile : 问题是,使用System.IO.Compression.ZipFile时出现此错误:

"Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory." “中央目录结尾中预期的条目数与中央目录中的条目数不对应。”

and when I use System.IO.Compression.DeflateStream , I get this error: 当我使用System.IO.Compression.DeflateStream ,出现此错误:

"Block length does not match with its complement." “块长度与其补码不匹配。”

Does not Windows zip use the same libraries? Windows zip不使用相同的库吗? Are the zip formats/algorithms different from .Net to Windows zip? 从.Net到Windows的zip格式/算法是否不同?

and if anyone can suggest a solution I would be thankful. 如果有人可以提出解决方案,我将不胜感激。

This may be yet another bug in the .NET implementations for deflate, zip, etc. support. 这可能是 另一个 错误在放气,压缩等支持.NET实现。 You should try DotNetZip instead. 您应该尝试使用DotNetZip

I found the issue, it seems there was nothing wrong with .net libraries to unzip the file, the problem was with the way the file written to disk after being uploaded to my asp.net application, a problem with encoding was in place, since I wrote the exact bytes into disk I was able to unzip it with .Net libraries. 我发现了问题,.net库似乎没有问题解压缩文件,问题在于文件上传到我的asp.net应用程序后写入磁盘的方式,编码存在问题,因为我将确切的字节写入磁盘,然后使用.Net库将其解压缩。

Thanks for everyone's contribution. 感谢大家的贡献。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM