用ICSharpCode.SharpZipLib压缩多个文件,然后用winrar打开报“这个压缩文件格式未知或者数据已经被损坏”错误,但用360 和7zip都能打开,大神们求解啊
internal static void DownloadForPressVer2(List<Model.FileEntity> files, string filename)
{
MemoryStream ms = new MemoryStream();
ZipOutputStream zipOutput = new ZipOutputStream(ms);
zipOutput.UseZip64 = UseZip64.Off;
Crc32 oCrc32 = new Crc32();
try
{
foreach (var file in files)
{
if (!File.Exists(HttpContext.Current.Server.MapPath(file.FilePath)))
{
continue;
}
byte[] buffer = null;
string currentFileName = file.FileName;
ZipEntry oZipEntry = new ZipEntry(currentFileName);
oZipEntry.CompressionMethod = CompressionMethod.Deflated;
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(file.FilePath), FileMode.Open, FileAccess.Read))
{
buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int) fs.Length);
}
oCrc32.Reset();
oCrc32.Update(buffer);
oZipEntry.Crc = oCrc32.Value;
zipOutput.PutNextEntry(oZipEntry);
zipOutput.Write(buffer, 0, buffer.Length);
}
}
catch (Exception)
{
throw;
}
finally
{
zipOutput.Finish();
zipOutput.Close();
}
byte[] bytes = ms.GetBuffer();
ms.Dispose();
DownloadFile(bytes, filename + ".zip");
}
internal static void DownloadForPressVer2(List<Model.FileEntity> files, string filename)
{
MemoryStream ms = new MemoryStream();
ZipOutputStream zipOutput = new ZipOutputStream(ms);
zipOutput.UseZip64 = UseZip64.Off;
Crc32 oCrc32 = new Crc32();
try
{
foreach (var file in files)
{
if (!File.Exists(HttpContext.Current.Server.MapPath(file.FilePath)))
{
continue;
}
byte[] buffer = null;
string currentFileName = file.FileName;
ZipEntry oZipEntry = new ZipEntry(currentFileName);
oZipEntry.CompressionMethod = CompressionMethod.Deflated;
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(file.FilePath), FileMode.Open, FileAccess.Read))
{
buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int) fs.Length);
}
oCrc32.Reset();
oCrc32.Update(buffer);
oZipEntry.Crc = oCrc32.Value;
zipOutput.PutNextEntry(oZipEntry);
zipOutput.Write(buffer, 0, buffer.Length);
}
}
catch (Exception)
{
throw;
}
finally
{
zipOutput.Finish();
zipOutput.Close();
}
byte[] bytes = ms.GetBuffer();
ms.Dispose();
DownloadFile(bytes, filename + ".zip");
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货