Unzip ZIP files


I have a method that decompresses ZIP files, but I have a problem when I try to unzip a file on my data server .


Public Function descomprimir(rutaZip As String, Optional carpetaDestino As String = "")

        If carpetaDestino = String.Empty Then
            carpetaDestino = "unzip"
        End If

        Dim shObj As Object = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"))
        Dim destino As String = Path.GetDirectoryName(rutaZip) & "\" & carpetaDestino

        'Crea el directorio donde se van a extraer los archivos
        Dim output As Object = shObj.NameSpace((destino))
        Dim input As Object = shObj.NameSpace((rutaZip))

        'Extrae los elementos del archivo zip
        output.CopyHere((input.Items), 4)

        Return destino
    End Function

The following line returns Nothing only if the file does not exist (in theory):

Dim input As Object = shObj.NameSpace((rutaZip))

But I have tried to put the previous line in a If File.Exists(rutaZip) ... and it always comes in because it detects that the file exists. (Either in a .zip of the data server, or of the local computer)

Example of the data server path:


Example local route:


(I accept suggestions on how to do it more easily) . Use NET 4.0

asked by cnbandicoot 21.04.2017 в 08:49

1 answer


Finally I did it with the DotNetZip library as follows:

Private Sub MyExtract()
   Dim ZipToUnpack As String = "\ServerData\data\docs\archivo.zip"
   Dim UnpackDirectory As String = "C:\Users\so\Desktop\prueba"
   Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
        Dim e As ZipEntry

        For Each e In zip1
            e.Extract(UnpackDirectory, ExtractExistingFileAction.OverwriteSilently)
    End Using
End Sub
answered by 21.04.2017 / 11:44