c# - ICSharpCode.SharpZipLib.Zip crc32

标签 c# asp.net sharepoint sharpziplib

我正在使用 ICSharpCode.SharpZipLib.Zip 压缩文件和文件夹,并使用 response.Binary write 将其作为内存流传递。

这是我的代码:

MemoryStream df= new MemoryStream();                
ZipOutputStream s = new ZipOutputStream(df);
s.SetLevel(9);

byte[] data = (byte[])file.OpenBinary();
s.Write(data, 0, data.Length);
s.Finish();

s.Close();
byte[] outBuf = df.GetBuffer();        
Response.Expires = 0;                 
Response.Buffer = true;                 
Response.ClearContent();                
Response.AddHeader("content-disposition", "inline; filename="out.zip");
Response.ContentType = "application/zip";
Response.BinaryWrite(outBuf);
HttpContext.Current.ApplicationInstance.CompleteRequest();

当我尝试打开 out.zip 文件时,提示该 zip 文件已损坏或 损坏,crc值显示为000000。

解决这个问题的方法是什么? 为什么会出现此错误?

最佳答案

我猜,你应该调用:

s.Flush();
df.Flush();

就在您调用 df.GetBuffer() 之前

关于c# - ICSharpCode.SharpZipLib.Zip crc32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5461207/

相关文章:

c# - ASP.NET如何将ASPX文件解析为可执行代码?

c# - 网络办公室 Hello World

c# - vs code c# omnisharp,如何调试外部库

asp.net - 如何在网格中按日期升序?

c# - 检测页面是否在 iframe 中 - 服务器端

sharepoint - TFS 2010 Sharepoint Web 部件错误

字典 <> 中的 C# linq

c# - 在不缓存数据的情况下覆盖 ActionResult

html - 如何使 Sharepoint 2010 Foundation 全局导航字体更大(自定义外观)

sharepoint - 在 CAML 查询共享点中使用 <In> 标签