我有一個數據庫中的ziparchive字節數組。當我從數據庫檢索數據並嘗試將其轉換回Ziparchive時,它會引發錯誤。有什麼辦法從字節數組轉換爲zipArchive?如何將字節數組轉換爲zip文件在c#中?
0
A
回答
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" };
相關問題
- 1. 如何將字節數組轉換爲ZIP文件
- 2. 如何將字節代碼轉換爲javascript中的zip文件
- 3. 將.zip文件轉換爲字節數組,然後從字節數組中重新創建.zip
- 4. 如何在PHP中將字節數組轉換爲文件?
- 5. 將C#字節數組轉換爲C++
- 6. 如何將struct數組轉換爲c#中的字節數組?
- 7. 如何將字節數組轉換爲C#中的雙數組?
- 8. 如何將zip文件轉換爲八位字節流
- 9. 如何將字節數組轉換爲Android中的PDF文件?
- 10. 如何將內存中的文件轉換爲字節數組?
- 11. 如何將字符串轉換爲C#中的字節數組?
- 12. 將C#字節數組轉換爲VB.NET
- 13. C:將字節數組轉換爲struct
- 14. 如何將Java字節數組轉換爲Scala字節數組?
- 15. 將NSData轉換爲base64encoded並將字節數組轉換爲C#
- 16. 如何將字符串數組轉換爲字節數組在c#中.net
- 17. BigInteger如何在Java中將字節數組轉換爲數字?
- 18. 如何將Short轉換爲Objective-c中的字節數組?
- 19. 如何將枚舉轉換爲Objective-C中的字節數組?
- 20. 如何將結構轉換爲C中的字節數組?
- 21. 如何將二進制文件轉換爲字節數組?
- 22. 如何將字節數組轉換爲圖像文件?
- 23. 如何將字節數組轉換爲文件
- 24. 如何將音頻文件轉換爲字節數組
- 25. 如何將html文件轉換爲字節數組使用angularjs
- 26. 如何將.wav文件轉換爲字節數組?
- 27. 如何將bytearray轉換爲zip文件
- 28. 在java中將二進制文件轉換爲字節數組?
- 29. 如何將十六進制格式的字節文本文件轉換爲字節數組在C#中
- 30. 將字節[]轉換爲.jpeg和zip
我的答案工作@Eraiarasu? – webmaster