So I converted a code from C# about Unziping a file using WindowsBase DLL:
public void UnZip(string pathToZipFile, string destinationPath) { try { using (Package package = ZipPackage.Open(pathToZipFile, FileMode.Open, FileAccess.Read)) { foreach (PackagePart part in package.GetParts()) { var target = Path.GetFullPath(Path.Combine(destinationPath, part.Uri.OriginalString.TrimStart('/'))); var targetDir = target.Remove(target.LastIndexOf('\\')); if (!Directory.Exists(targetDir)) Directory.CreateDirectory(targetDir); using (Stream source = part.GetStream(FileMode.Open, FileAccess.Read)) { source.CopyTo(File.OpenWrite(target)); } } } } catch (Exception ex) { throw new Exception(ex.Message + " (Event: UnZip)"); } }
After conversion to VB.NET
Public Sub UnZip(ByVal pathToZipFile As String, ByVal destinationPath As String) Try Using package As Package = ZipPackage.Open(pathToZipFile, FileMode.Open, FileAccess.Read) For Each part As PackagePart In package.GetParts() Dim target = Path.GetFullPath(Path.Combine(destinationPath, part.Uri.OriginalString.TrimStart("/"c))) Dim targetDir = target.Remove(target.LastIndexOf("\"c)) If Not Directory.Exists(targetDir) Then Directory.CreateDirectory(targetDir) End If Using source As Stream = part.GetStream(FileMode.Open, FileAccess.Read) source.CopyTo(File.OpenWrite(target)) End Using Next End Using Catch ex As Exception Throw New Exception(ex.Message + " (Event: UnZip)") End Try End Sub
I got error "'CopyTo' is not a member of 'System.IO.Stream'.