Unzip ZIP files

4

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

Method:

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
        IO.Directory.CreateDirectory(destino)
        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:

\ServerData\data\docs\archivo.zip

Example local route:

C:\Users\so\Desktop\archivo.zip

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

    
asked by cnbandicoot 21.04.2017 в 08:49
source

1 answer

1

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)
        Next
    End Using
End Sub
    
answered by 21.04.2017 / 11:44
source