Я сжал массив байтов, используя ZipArchive.При выполнении описанного ниже метода, он предлагает сохранить сжатую папку, но выдает ошибку: «Окно не может открыть папку. Сжатая (сжатая) папка недопустима» при попытке открыть папку. Ниже приведен код для архивирования файла.
public void CompressFile() {
using (var compressedFileStream = new MemoryStream())
//Create an archive and store the stream in memory.
using (var zipArchive = new ZipArchive(compressedFileStream,ZipArchiveMode.Create, true))
{
//Create a zip entry for each attachment
var zipEntry = zipArchive.CreateEntry("FY14 statements");
byte[] pdf = _dmsbl.DocumentData(4);
//Get the stream of the attachment
using (var originalFileStream = new MemoryStream(pdf))
using (System.IO.Stream entryStream = zipEntry.Open())
{
originalFileStream.CopyTo(entryStream);
}
SendOutZip(compressedFileStream.ToArray(), "FileName.zip");
}
}
private void SendOutZip(byte[] zippedFiles, string filename)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/x-compressed";
Response.Charset = string.Empty;
Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.BinaryWrite(zippedFiles);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.End();
}