2016-08-18 105 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

相關問題