使用ICSharpCode.SharpZipLib.dll压缩多个文件到rar
主要功能代码如下:using (System.IO.FileStream ZipFile = new FileStream(zipedFile, FileMode.Create))
{
 using (ZipOutputStream ZipStream = new ZipOutputStream(ZipFile))
  {
    using (System.IO.FileStream StreamToZip = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
    {                        ZipEntry ZipEntry = new ZipEntry(fileName);
                        ZipStream.PutNextEntry(ZipEntry);                        byte[] setbuffer = new byte[StreamToZip.Length];
                        StreamToZip.Read(setbuffer, 0, setbuffer.Length);
                        ZipStream.Write(setbuffer, 0, setbuffer.Length);                        StreamToZip.Close();
    }
  }
}
下载后用好压等压缩工具解压都没问题,用winrar解压异常。
用winrar打开后发现CRC32值为00000000,使用【工具-修复】后就可以解压了。有知道原因的吗?

解决方案 »

  1.   

    问题已解决,一下
    主要是Response响应文件时出的错,注意两点即可
    1、生成的压缩文件不要rar要zip
    2、Response代码            Response.Clear();
                Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
                Response.ContentType = "application/octet-stream";
                Response.Filter.Close();
                Response.WriteFile(filePath);
                Response.Flush();
                Response.End();
    纠结好几天,终于解决!