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