?
Solved

7 Zip Vb.net

Posted on 2011-05-09
25
Medium Priority
?
4,413 Views
Last Modified: 2012-05-11
Hi All

Im trying to get a vb.net program to decompress 7 zip file.... which i cant seem to find any code example anywhere.

Anyidea how to do this? Code would be nice

Cheers

Matt
0
Comment
Question by:Matb396
  • 12
  • 11
  • +1
25 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 35718906
0
 

Author Comment

by:Matb396
ID: 35719007
i seem to get an error "zipexception was unhandled wrong local header 0x44909d1f"

using code:
Public Sub ExtractArchive(ByVal zipFilename As String, ByVal ExtractDir As String)
        Dim Redo As Integer = 1
        Dim MyZipInputStream As ZipInputStream
        Dim MyFileStream As FileStream
        MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, FileMode.Open, FileAccess.Read))
        Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
        Directory.CreateDirectory(ExtractDir)
        While Not MyZipEntry Is Nothing
            If (MyZipEntry.IsDirectory) Then
                Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
            Else
                If Not Directory.Exists(ExtractDir & "\" & _
                Path.GetDirectoryName(MyZipEntry.Name)) Then
                    Directory.CreateDirectory(ExtractDir & "\" & _
                    Path.GetDirectoryName(MyZipEntry.Name))
                End If
                MyFileStream = New FileStream(ExtractDir & "\" & _
                  MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
                Dim count As Integer
                Dim buffer(4096) As Byte
                count = MyZipInputStream.Read(buffer, 0, 4096)
                While count > 0
                    MyFileStream.Write(buffer, 0, count)
                    count = MyZipInputStream.Read(buffer, 0, 4096)
                End While
                MyFileStream.Close()
            End If
            Try
                MyZipEntry = MyZipInputStream.GetNextEntry
            Catch ex As Exception
                MyZipEntry = Nothing
            End Try
        End While
        If Not (MyZipInputStream Is Nothing) Then MyZipInputStream.Close()
        If Not (MyFileStream Is Nothing) Then MyFileStream.Close()
    End Sub

Open in new window


error happens on
 
    Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry

Open in new window


anyidea why?


0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35719044
7Zip is based upon the LZMA format so I would guess that your "ZipInputStream" implementation is designed to work with a different zipping algorythm. With this in mind, probably the best approach would be to use the 7zip command line utility to extract the archive. This does require you to install the 7zip binaries on the machine so you will have to decide whether that is viable.

Here's a page detailing the command line arguments:

http://www.dotnetperls.com/7-zip-examples

Alternatively, if you really want to get into the nuts and bolts, you can use the 7Zip SDK which includes a C# Implementation of the LZMA algorythm (which is was 7zip uses):

http://www.7-zip.org/sdk.html
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Matb396
ID: 35719183
I cant get that to work either.... i can in the program but not in the script

i've tire:

o:\7-zip\7zg.exe e o:\test.7
o:\7-zip\7zg e o:\test.7
o:\7zg.exe e o:\test.7
o:\7zg.exe e test.7
o:\7zg e test.7

keep getting the same error

"cannot find archive"

anyideas?

0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35719272
I would wrap the location of the archive file in quotes and make sure the entire directory is included. The other thing that may be causing you an issue is the file location. This is a stab in the dark but is "O" a mapped drive?

0
 
LVL 2

Accepted Solution

by:
Dhugal_L earned 2000 total points
ID: 35719299
Finally it doesn't look like you're including the whole file extension. Don't 7Zip files and an extension of "7Z" or "7Zip" not just "7"?
0
 

Author Comment

by:Matb396
ID: 35719465
tried, yet still the same message.. and yes map drive but tired on c, still same message

i think it might be 7z but the file i got is test.7 dont know why there isn't a "z" on the end...
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35719868
Have you tried running the command from the command line?
The only other thing might be a problem with the permissions your application is running under.
0
 

Author Comment

by:Matb396
ID: 35719924
sorry what do you mean "command from the command line" ?? ive been entering it in to run???
0
 

Author Comment

by:Matb396
ID: 35719928
o and permissions, im logged in as the administrator
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35719941
Ah - I just spotted the problem - 7zg.exe is the GUI version... use 7z.exe, this is the command line version. As stated in the 7zip readme:


  This distribution contains the following files:

  7zFM.exe      - 7-Zip File Manager
  7-zip.dll     - Plugin for Windows Shell and for 7-Zip File Manager
 7zg.exe       - GUI module
  7z.exe        - Command line version

  7z.dll        - 7-Zip engine module
  7z.sfx        - SFX module (Windows version)
  7zCon.sfx     - SFX module (Console version)
0
 

Author Comment

by:Matb396
ID: 35719978
i did try that before but didn't work..... all it does is open the command prompt windows then close straight away before you can read it.... o and nothing happens

any other idea?
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35720020
See the attached example... I had to run the command line as an admin using the "Run As Administrator" option. Command Line Running as Administrator
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35720040
in the run dialog type in "CMD" and hit return.. this brings up a command window. Alternatively find the CMD.exe (normally located in c:\Windows\System32\cmd.exe), right click it and choose "Run as Administrator".
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35720045
"i did try that before but didn't work..... all it does is open the command prompt windows then close straight away before you can read it.... o and nothing happens"

You must run it from the command line.. NOT from run or by double clicking it.
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35720061
0
 

Author Comment

by:Matb396
ID: 35720129
still not working... screen
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35721009
so what happens if you open the command line and type in "C:\7-zip\test.7"?
0
 

Author Comment

by:Matb396
ID: 35721108
Same...
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35721110
And does it work if you open it with 7zip GUI?
0
 

Author Comment

by:Matb396
ID: 35721120
yep
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35721357
As far as I can see there can only be a couple of things causing this:

1) You're referencing an invalid location/filename. Can you create a new 7zip file using the 7zip application on the root of the C:\ drive and retest it using this new file please?

2) There is some kind of permissions issue. This is unlikely as you're running the command line as an administrator but referencing files on a mapped drive may be an issue. Again, testing with a new file on the root of a local drive should help.
0
 

Author Comment

by:Matb396
ID: 35721445
works fine.... i've tried with a different file from the same source.... same message

0
 

Author Closing Comment

by:Matb396
ID: 35721464
.z
0
 
LVL 2

Expert Comment

by:Dhugal_L
ID: 35721655
We got there in the end, thanks for accepting my solution.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question