次のコードに問題があります。会社の都合で Windows 2003 を使用する必要があります。彼らはこのシステムを使用しています。このコードは、Windows XP で動作している間は動作しません。このコードはzipファイルを生成し、Windowsエクスプローラーで開くと、「破損したファイル」というエラーが表示されます。私は DotNetZip.dll と特に Ionic.Zip を使用しています。zip ファイルは HTTP 応答ストリームで送信されます。
誰か助けてくれませんか?回答ありがとうございます。
私の機能:
public void Zip()
{
Response.ContentType = "application/octet-stream";
Response.AppendHeader("content-disposition", "attachment; filename=\"myFile.zip\"");
byte[] buffer = new byte[4096];
ZipOutputStream zipOutputStream = new ZipOutputStream(Response.OutputStream);
zipOutputStream.CompressionLevel = Ionic.Zlib.CompressionLevel.Level3;
string[] filestozip = Directory.GetFiles("C:\\myFolderToZip", "*.*", SearchOption.AllDirectories);
foreach (string fileName in filestozip)
{
Stream fs = File.OpenRead(fileName);
zipOutputStream.PutNextEntry(fileName.Replace(dir + "\\", ""));
int count = fs.Read(buffer, 0, buffer.Length);
while (count > 0)
{
zipOutputStream.Write(buffer, 0, count);
count = fs.Read(buffer, 0, buffer.Length);
Response.Flush();
}
fs.Close();
}
zipOutputStream.Close();
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}