Zipping & Unzipping Using Shell32.dll
Ok i didn't like the idea of having to have a 3rd party application stuck in my apps directory so i asked for help on how to do it with the windows built in Shell32.dll. This is what i found out.
To use this in your own project you need to make a reference to C:\Windows\System32\shell32.dll
VB.net Code:
'Remeber to create a reference to C:\Windows\System32\shell32.dll
'Project > Add Reference > Browse and then navigate to the Windows\System32\shell32.dll.
Private Sub ExtractZip(ByVal zipFile As String, ByVal destination As String)
Dim shell As Shell32.Shell = New Shell32.Shell
shell.NameSpace(destination).CopyHere(shell.NameSpace(zipFile).Items, Nothing)
shell = Nothing
End Sub
Public Sub ZipFile(ByVal strFileToZip, ByVal strTargetZip)
CreateEmptyZip(strTargetZip)
Try
CreateObject("Shell.Application").Namespace(strTargetZip).CopyHere(strFileToZip)
Catch ex As Exception
End Try
End Sub
Private Sub CreateEmptyZip(ByVal sPath As String)
Dim strZIPHeader As String
strZIPHeader = Chr(80) & Chr(75) & Chr(5) & Chr(6) & String.Format(18, 0)
CreateObject("Scripting.FileSystemObject").CreateTextFile(sPath).Write(strZIPHeader)
End Sub
Re: Zipping & Unzipping Using Shell32.dll
Quote:
Originally Posted by
Emcrank
Ok i didn't like the idea of having to have a 3rd party application stuck in my apps directory so i asked for help on how to do it with the windows built in Shell32.dll. This is what i found out.
To use this in your own project you need to make a reference to C:\Windows\System32\shell32.dll
VB.net Code:
'Remeber to create a reference to C:\Windows\System32\shell32.dll
Private Sub ExtractZip(ByVal zipFile As String, ByVal destination As String)
Dim shell As Shell32.Shell = New Shell32.Shell
shell.NameSpace(destination).CopyHere(shell.NameSpace(zipFile).Items, Nothing)
shell = Nothing
End Sub
Public Sub ZipFile(ByVal strFileToZip, ByVal strTargetZip)
CreateEmptyZip(strTargetZip)
Try
CreateObject("Shell.Application").Namespace(strTargetZip).CopyHere(strFileToZip)
Catch ex As Exception
End Try
End Sub
Private Sub CreateEmptyZip(ByVal sPath As String)
Dim strZIPHeader As String
strZIPHeader = Chr(80) & Chr(75) & Chr(5) & Chr(6) & String.Format(18, 0)
CreateObject("Scripting.FileSystemObject").CreateTextFile(sPath).Write(strZIPHeader)
End Sub
I wish all the code where as this.
simple and elegant.
Thanks!
Re: Zipping & Unzipping Using Shell32.dll
Re: Zipping & Unzipping Using Shell32.dll
please how can i use this to extract archice
C:/a.zip
to
C:/a
please help
where can put directories and file in source code
Re: Zipping & Unzipping Using Shell32.dll
Basic question, I know, but in the first line is the admonition to
Quote:
Remeber to create a reference to C:\Windows\System32\shell32.dll
How exactly does one do that, please?
Many thanks!
Edit:
Ahhh... nevermind! A few minutes of poking around & I found it.
For anybody who hasn't seen it before (i.e. if you are where I was 10 minutes ago), in VS2010 go to the menu bar & Project > Add Reference > Browse and then navigate to the Windows\System32\shell32.dll.
And for everyone who already knew that, please disregard all!