Private Function Compress(data As Byte()) As Byte()
Dim result As Byte() = Nothing
Try
Using memoryStream As New MemoryStream()
Dim method As ZipCompression = ZipCompression.Deflate64
Using zipOutputStream As New ZipOutputStream(memoryStream, method)
Using writer As New StreamWriter(zipOutputStream)
writer.Write(data)
writer.Flush()
result = memoryStream.ToArray()
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return result
End Function
Private Function UnCompress(data As Byte()) As Byte()
Dim result As Byte() = Nothing
Try
Using memoryStream As New MemoryStream(data)
Using zipInputStream As New ZipInputStream(memoryStream)
Using reader As New StreamReader(zipInputStream)
result = memoryStream.ToArray
End Using
End Using
End Using
Catch ex As Exception
End Try
Return result
End Function
01.private static void UnpackAndSaveFile(ZipPackageEntry entry, string destinationPath)02. {03. Stream stream = entry.OpenInputStream();04. var fileName = destinationPath + "\\" + entry.FileNameInZip;05. 06. var directoryName = Path.GetDirectoryName(fileName);07. 08. if (directoryName != null)09. {10. if (!Directory.Exists(directoryName))11. {12. Directory.CreateDirectory(directoryName);13. }14. 15. if (System.IO.File.Exists(fileName))16. {17. System.IO.File.Delete(fileName);18. }19. 20. StreamReader reader = new StreamReader(stream);21. string text = reader.ReadToEnd();22. File.WriteAllText(fileName, text); 23. }24. }Dim ArqZip As String = "Order.zip"Dim Package As ZipPackage = ZipPackage.CreateFile(PathCart & ArqZip) For Each ArqPDF In ArqsPDF Try Package.Add(CaminhoCart & ArqPDF) Catch ex as exception TextNotifi.Text = ex.Message TextNotifi.Height = 150 TextNotifi.Show() Exit For End TryNext Package.Close(False)