2016-08-18 142 views

回答

1

从这个answer我认为这是可能你的流字节数组转换为zip压缩包:

using (var compressedFileStream = new MemoryStream()) { 
    //Create an archive and store the stream in memory. 
    using (var zipArchive = new ZipArchive(compressedFileStream, ZipArchiveMode.Update, false)) { 
     foreach (var caseAttachmentModel in caseAttachmentModels) { 
      //Create a zip entry for each attachment 
      var zipEntry = zipArchive.CreateEntry(caseAttachmentModel.Name); 

      //Get the stream of the attachment 
      using (var originalFileStream = new MemoryStream(caseAttachmentModel.Body)) { 
       using (var zipEntryStream = zipEntry.Open()) { 
        //Copy the attachment stream to the zip entry stream 
        originalFileStream.CopyTo(zipEntryStream); 
       } 
      } 
     } 

    } 

    return new FileContentResult(compressedFileStream.ToArray(), "application/zip") { FileDownloadName = "Filename.zip" }; 
} 

这里,用线new FileContentResult(compressedFileStream.ToArray(), "application/zip") { FileDownloadName = "Filename.zip" };,如果你已经转换成zip文件,那么你可以将您的流字节数组到这样的zip存档:

new FileContentResult(your_stream_byte_array, "application/zip") { FileDownloadName = "Filename.zip" }; 
+0

感谢您的回复。我已经创建了存储在数据库中的zipfile和流字节数组。现在我想将该字节数组转换为ZipArchive – Eraiarasu

+0

所以我想最后一步是使用流字节数组并创建您的zip存档,如下所示:'new FileContentResult(your_stream_byte_array,“application/zip”){FileDownloadName =“Filename.zip” };'这里, – webmaster

+0

它工作吗? @Eraiarasu – webmaster

相关问题