how to unzip with a progress bar? [solved]

Aug 12, 2009 at 2:32 AM

Imports Ionic.Zip

Public Class Frm_Patcher

    Private Shared justHadByteUpdate As Boolean = False

    Public Shared Sub MyExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
        If (e.EventType Is ZipProgressEventType.Extracting_EntryBytesWritten) Then
            If ExtractTest.justHadByteUpdate Then
                Console.SetCursorPosition(0, Console.CursorTop)
            End If
            Console.Write("   {0}/{1} ({2:N0}%)", e.BytesWritten, e.TotalBytesToWrite, (CDbl(e.BytesWritten) / (0.01 * e.TotalBytesToWrite)))
            ExtractTest.justHadByteUpdate = True
        ElseIf (e.EventType Is ZipProgressEventType.Extracting_BeforeExtractEntry) Then
            If ExtractTest.justHadByteUpdate Then
                Console.WriteLine()
            End If
            Console.WriteLine("Extracting: {0}", e.NameOfLatestEntry)
            ExtractTest.justHadByteUpdate = False
        End If
    End Sub


    Private Sub MyExtract()
        Dim Overwrite As ExtractExistingFileAction = ExtractExistingFileAction.OverwriteSilently
        Dim ZipToUnpack As String = "C1P3SML.zip"
        Dim UnpackDirectory As String = "Extracted Files"
        StatusMessage.Text = String.Format("Extracting file {0} to {1}", ZipToUnpack, UnpackDirectory)
        Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
            AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress
            Dim e As ZipEntry
            ' here, we extract every entry, but we could extract conditionally,
            ' based on entry name, size, date, checkbox status, etc.   
            For Each e In zip1
                e.Extract(UnpackDirectory, Overwrite)
            Next
        End Using
    End Sub

    Private Sub Frm_Patcher_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MyExtract()
    End Sub
End Class

 

this is the code im useing copyed it right from the examples page.. i past it into my form like so and i get all sorts of errors.. what do i do? i want to make my fiel unzip and show its progress in progressbar1. sorry if this sounds kinda newbie but this is my first project in vs2008 im normally useing vb6 so .net is new to me this is actaully the only one i have got to work so far. i can exstract the file useing the example on the home page but i cant get the progress bar code here to work. and then once i get it working how do i call it to make th bar work.

 

here are the errors

i have colored red and underlined all the lines thats underlined in my code.

Error    1    'Is' operator does not accept operands of type 'Ionic.Zip.ZipProgressEventType'. Operands must be reference or nullable types.
Error    2    'Is' operator does not accept operands of type 'Ionic.Zip.ZipProgressEventType'. Operands must be reference or nullable types.
Error    3    Name 'ExtractTest' is not declared.
Error    4    'BytesWritten' is not a member of 'Ionic.Zip.ExtractProgressEventArgs'.
Error    5    'TotalBytesToWrite' is not a member of 'Ionic.Zip.ExtractProgressEventArgs'.
Error    6    'BytesWritten' is not a member of 'Ionic.Zip.ExtractProgressEventArgs'.
Error    7    'TotalBytesToWrite' is not a member of 'Ionic.Zip.ExtractProgressEventArgs'.
Error    8    Name 'ExtractTest' is not declared.
Error    9    'Is' operator does not accept operands of type 'Ionic.Zip.ZipProgressEventType'. Operands must be reference or nullable types.
Error    10    'Is' operator does not accept operands of type 'Ionic.Zip.ZipProgressEventType'. Operands must be reference or nullable types.
Error    11    Name 'ExtractTest' is not declared.
Error    12    'NameOfLatestEntry' is not a member of 'Ionic.Zip.ExtractProgressEventArgs'.
Error    13    Name 'ExtractTest' is not declared.

 

if you need anymore info let me know please im watching this post

Coordinator
Aug 12, 2009 at 3:20 AM

Spidey,

check out the examples on msdn.

There is a VB.NET project that compiles and runs; it uses a progressbar.   There's also a C# app that uses a progressbar.

 

Aug 12, 2009 at 4:18 AM

i tryed that out its ziping the file i need to unzip it

Coordinator
Aug 12, 2009 at 4:56 AM

ok, well, instead of using the Saving_... event types, use the Extracting_... event types.

 

Private Sub zip_ExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
    If (e.EventType = (ZipProgressEventType.Extracting_ExtractEntryWouldOverwrite Or ZipProgressEventType.Reading_ArchiveBytesRead)) Then
         StepEntryProgress(e)
    ElseIf (e.EventType = ZipProgressEventType.Extracting_BeforeExtractAll) Then
         StepArchiveProgress(e)
    End If
    If  _setCancel Then
        ' this Boolean would be set in a event handler for the cancel button
e.Cancel = True End If End Sub
Private Sub StepEntryProgress(ByVal e As ZipProgressEventArgs)
    If  progressBar2.InvokeRequired Then
         progressBar2.Invoke(New ZipProgress(AddressOf StepEntryProgress), New Object() { e })
    ElseIf Not _operationCanceled Then
        If (progressBar2.Maximum = 1) Then
            ' first time through for the current entry
progressBar2.Maximum = CInt(e.TotalBytesToTransfer) 'set a label with status information
lblStatus.Text = String.Format("{0} of {1} files...({2})", (_nFilesCompleted + 1), _totalEntriesToProcess, e.CurrentEntry.FileName) End If ' do this every time
progressBar2.Value = IIf((e.BytesTransferred >= progressBar2.Maximum), progressBar2.Maximum, e.BytesTransferred) MyBase.Update End If End Sub

 

Private Sub StepArchiveProgress(ByVal e As ZipProgressEventArgs)
    If progressBar1.InvokeRequired Then
        progressBar1.Invoke(New ZipProgress(AddressOf StepArchiveProgress), New Object() { e })
    ElseIf Not _operationCanceled Then
        _nFilesCompleted = _nFilesCompleted+1
progressBar1.PerformStep progressBar2.Value = progressBar2.Maximum = 1 MyBase.Update End If End Sub

 

I guess you'll be able to figure out the rest.

 

 

Aug 12, 2009 at 6:02 AM
Edited Aug 12, 2009 at 6:03 AM

ok this is what i got so far no errors it exstracts the fiel just fine but there is no progress bars ether one..

 

also i would like to not if it makes it simpler i dont need 2 progress bars one showing over all on one showing files.. i just need the one showing ovr all but im not sure yt how to remove the extra till i get them working.. so if you would like to remove it to make it easyer on you be my guest.

 

anyways this is what i got

 

Imports Ionic.Zip



Public Class Frm_Patcher

    Private _operationCanceled As Boolean
    Private _nFilesCompleted As Integer
    Private _totalEntriesToProcess As Integer

    Private Delegate Sub ZipProgress(ByVal e As SaveProgressEventArgs)


    Private Sub zip_ExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
        If (e.EventType = (ZipProgressEventType.Extracting_ExtractEntryWouldOverwrite Or ZipProgressEventType.Reading_ArchiveBytesRead)) Then
            StepEntryProgress(e)
        ElseIf (e.EventType = ZipProgressEventType.Extracting_BeforeExtractAll) Then
            StepArchiveProgress(e)
        End If
    End Sub

    Private Sub StepEntryProgress(ByVal e As ZipProgressEventArgs)
        If progressBar2.InvokeRequired Then
            progressBar2.Invoke(New ZipProgress(AddressOf StepEntryProgress), New Object() {e})
        ElseIf Not _operationCanceled Then
            If (progressBar2.Maximum = 1) Then
                ' first time through for the current entry
                progressBar2.Maximum = CInt(e.TotalBytesToTransfer)
                'set a label with status information
                Txt_Output.Text = String.Format("{0} of {1} files...({2})", (_nFilesCompleted + 1), _totalEntriesToProcess, e.CurrentEntry.FileName)
            End If
            ' do this every time
            progressBar2.Value = IIf((e.BytesTransferred >= progressBar2.Maximum), progressBar2.Maximum, e.BytesTransferred)
            MyBase.Update()
        End If
    End Sub



    Private Sub StepArchiveProgress(ByVal e As ZipProgressEventArgs)
        If progressBar1.InvokeRequired Then
            progressBar1.Invoke(New ZipProgress(AddressOf StepArchiveProgress), New Object() {e})
        ElseIf Not _operationCanceled Then
            _nFilesCompleted = _nFilesCompleted + 1
            progressBar1.PerformStep()
            progressBar2.Value = progressBar2.Maximum = 1
            MyBase.Update()
        End If
    End Sub

    Private Sub MyExtract()
        Dim Overwrite As ExtractExistingFileAction = ExtractExistingFileAction.OverwriteSilently
        Dim ZipToUnpack As String = "C1P3SML.zip"
        Dim UnpackDirectory As String = "Extracted Files"
        Txt_Output.Text = String.Format("Extracting file {0} to {1}", ZipToUnpack, UnpackDirectory)
        Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
            Me._totalEntriesToProcess = zip1.EntryFileNames.Count
            Me.SetProgressBars()
            AddHandler zip1.ExtractProgress, New EventHandler(Of ExtractProgressEventArgs)(AddressOf zip_ExtractProgress)
            Dim e As ZipEntry
            ' here, we extract every entry, but we could extract conditionally,
            ' based on entry name, size, date, checkbox status, etc.   
            For Each e In zip1
                e.Extract(UnpackDirectory, Overwrite)
            Next
        End Using
    End Sub

    Private Sub Cmd_Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmd_Exit.Click
        Me._operationCanceled = False
        Me._nFilesCompleted = 0
        MyExtract()
    End Sub

    Private Sub SetProgressBars()
        If Me.ProgressBar1.InvokeRequired Then
            Me.ProgressBar1.Invoke(New MethodInvoker(AddressOf SetProgressBars))
        Else
            Me.ProgressBar1.Value = 0
            Me.ProgressBar1.Maximum = Me._totalEntriesToProcess
            Me.ProgressBar1.Minimum = 0
            Me.ProgressBar1.Step = 1
            Me.ProgressBar2.Value = 0
            Me.ProgressBar2.Minimum = 0
            Me.ProgressBar2.Maximum = 1
            Me.ProgressBar2.Step = 2
        End If
    End Sub
End Class

Coordinator
Aug 12, 2009 at 8:05 AM

 

ok, try this example.

Aug 12, 2009 at 5:30 PM

that worked great and from that i can g mine working thanks alot.. also on a side note the refrance for ionic.zip was not found in the unzip project i had to add it myself.. dont knwo if you want to add that to it before others download but after adding it its wroking great..

 

one thing though. y does it take so much to get a progress bar to move lol.. i mean bfore in vb6 it was a matter of adding a call to the unzip line to see how many files where in the zip then makeing the progressbar max the filel count then counting up the bar +1 each file.. all added about 5 lines max if that many.. but this wow that was alot of stuff to get the bar to move. is there a simpler way to do it and your jsut donig it the long way to do all the error checking and such? you cant just say

for e < filecount

progressbar1.value = progressbar.value+1

unzip(e) 'or whatever to unzip

loop

 

something simple like that is what i used in vb is it jsut .net thats makeing it so much more info needed now? or is it siply jsut how the dll was made to work?

 

anyways thanks alot for your help i really appriciae it.

ps sorry for the speling just work up still half awake lol.

Coordinator
Aug 12, 2009 at 5:56 PM

You can compile code and add references to Visual Studio projects, you can reason about application design, but you're not able to spell or hit the Shift key?  I think maybe it's not that you're half awake but just that you enjoy "not speling".   whatever.

Yes, there are simpler ways to do it.  What you described would work just fine, if you don't want a cancel capability.  

If you want to be able to cancel the extract part way through, then you need to do the extract on a background thread. 

If you do the extract in the button click event, then the extraction is being performed on the main, "UI" thread.  Suppose the extraction takes 3 minutes - that can happen for big zip files.  If the user clicks a cancel button during those three minutes, the application won't respond, because the main UI thread is busy extracting.  When the extraction is done, the unzip button click event will complete, and then the cancel button click event will run.  But by that time the unzip work is done.  This obviously is not a responsive UI.

To have a responsive UI, the application cannot do long-running work on the UI thread. That way the UI thread is always available for UI events - button clicks or whatever.

So I had to kick-off a thread to do the extraction.  That's half the complexity.  The next half is - it's not possible to update the UI (like advance the progress bar) from the background thread.  So, for each update of the progressbar (or enable/disable a button, etc), I need a separate method that calls to "Control.InvokeRequired", and if that returns true, the method then calls itself via Invoke.  This switches threads to allow the update of the control to happen on the main UI thread.

All that complexity is necessary if you want a cancellable UI.

It has nothing to do with DotNetZip.   This is the way to make a cancellable UI in .NET WinForms, whenever you run a long-running task in response to a button click: Do the work on the background thread, and Control.Invoke() to update the UI.

I did it the long way because it's an example, and I kinda want to publish good examples, in case people copy them.

Actually, thinking about it, there is a bit of over-complexity just in the extraction.  I call ExtractAll() and use a ExtractProgress method, but the way you described it - iterating through the entries and calling Extract() on each one - would work and would eliminate the need for the ExtractProgress event. The ExtractProgress is really necessary if:

  • you want to have a progressbar and you call ExtractAll, OR
  • you want to have 2 progress bars, one for the entry, and one for the entire archive.

 But even without the ExtractProgress, you still need the background thread and the Control.InvokeRequired.

 

Aug 12, 2009 at 6:19 PM
Cheeso wrote:

You can compile code and add references to Visual Studio projects, you can reason about application design, but you're not able to spell or hit the Shift key?  I think maybe it's not that you're half awake but just that you enjoy "not speling".   whatever.

Why do you have to be so mean :P I did not know I was annoying you that much lol.. I apologized for the spelling. A few things are equating to the spelling.. A bad keyboard that wants to mis half the t's and i's I hit. Dyslexia, and the fact of being half awake. And I never was much on grammar hence the not hitting shift.

I was simply just asking a question. And you answered it flawlessly as a matter of fact.. And it makes sense like I said in the beginning this is my first .net project normally I’m using vb6 and I can only go from what I know there. So I did not know if it was something to do with .net or the dll or if it was you just doing it in example format to produce a good example for others to follow also. I’m sure everyone appreciates what you’re doing as much as I do.

 

That makes sense now that you would have to do it such a long way to push it to the background and so on.. But what if you don’t have a cancel event is there a simple example you could show me for something like that? Because the program I’m making is a patcher it downloads the zip files then extracts them to the right place for them to be all on load of the form there will actually be no buttons for the user to click until after the patch process is done..

 

If you do not wish to help anymore on this topic I understand you did help me and I have something that works even though it’s a bit over complicated for what I need it works. So I’m happy with that. I’m just trying to understand all the workings of a dll I’m trying to use because this is one I see myself using a lot.

 

Again please accept my apologies for the spelling and what not and for taking up so much of your time on this. And thanks for all the help you have given.

Coordinator
Aug 12, 2009 at 7:26 PM
Edited Aug 12, 2009 at 7:30 PM

no offense intended.   You don't need to explain anything, write however ya want.

For a really simple unzip app that displays a graphical UI, produce a simple WinForms project.  Add a single label (label1) and a single progressbar (progressBar1).  Then include the following code.  You may have to change the name from MyForm to whatever your form is (in 2 places).     Somehow you need to pass in the name of the zip file to extract and the directory to which you want to extract.  Probably on the command line as arguments.

Private Sub MyForm_Shown(ByVal sender As Object, ByVal e As EventArgs) Handles MyForm.Shown
    Try 
        Using zip As ZipFile = ZipFile.Read(zipfile)
            Me.progressBar1.Maximum = zip.Entries.Count
            Dim entry As ZipEntry
            For Each entry In zip
                Me.label1.Text = entry.FileName
                MyBase.Update
                entry.Extract(extractDirectory, ExtractExistingFileAction.OverwriteSilently)
                Me.progressBar1.PerformStep
                MyBase.Update
                ' sleep because it's too fast otherwise.
                Thread.Sleep(50)
            Next
        End Using
    Catch ex1 As Exception
        Me.label1.Text = ("Exception: " & ex1)
    End Try
    ' delay for a second after complete, to allow user to gaze
    Dim timer1 As New Timer(1000)
    timer1.Enabled = True
    timer1.AutoReset = False
    AddHandler timer1.Elapsed, New ElapsedEventHandler(AddressOf Me.OnTimerEvent)
End Sub

Public Sub OnTimerEvent(ByVal source As Object, ByVal e As EventArgs)
    MyBase.Close
End Sub

 

And, I wouldn't put your download-and-unzip logic in the Load event. I would put it in the Shown event, which happens after the form Load. It is after Form load that the form is visible. So if you do work inside Load() sometimes, you don't get to see the update of the UI.

 

Aug 13, 2009 at 7:53 AM

Sorry took so long to reply i took my kid to the beach today and she keep me out all day.. I must say that code looks lot more like what I was looking for lol thanks a lot.. But I’m having problems of coarse this stuff cant just work like its suppose to lol

 

First off I want to understand I’m new to this mybase deal what is that?

MyBase.Update()

MyBase.Close

 

I don’t understand what’s that doing.. Is it needed?

Then my errors..

Using zip As ZipFile = ZipFile.Read(zipfile)

I don't understand why. It’s worked all the other times it’s exactly the same line as before but I’m getting this error from it
'Read' is not a member of 'String'.

next problem is

Me.label1.Text = ("Exception: " & ex1)

it seems that ex1 cannot be converted to a string..
Operator '&' is not defined for types 'String' and 'System.Exception'.

If I remove everything except ex1 it says it can’t be converted to string

next problem I fixed but wanted to note it in case anyone else is following this

Thread.Sleep(50)

gave an error I fixed it by changing to

System.Threading.Thread.Sleep(50)

next problem well this is the last one but it’s a few..

Dim timer1 As New Timer(1000)
        timer1.Enabled = True
        timer1.AutoReset = False
        AddHandler timer1.Elapsed, New ElapsedEventHandler(AddressOf Me.OnTimerEvent)

I get error at the 1000
autoreset (I don’t even think that’s a call from timers at least it’s not listed in the options for auto fill
and ElapsedEventHandler is underlined

Value of type 'Integer' cannot be converted to 'System.ComponentModel.IContainer'.


'AutoReset' is not a member of 'System.Windows.Forms.Timer'.


Type 'ElapsedEventHandler' is not defined.

Ok that’s is all the errors are listed and what I think if anything.. My biggest thing is I want you to explain that MyBase part..
I’m not sure what that is and having a problem finding something on google about it that I can understand at lest lol..
I just hate using calls and not knowing what they do this is all a learning experience so I like to learn what I can from it.

Coordinator
Aug 13, 2009 at 4:28 PM

Hello Spidey. spending the day at the beach is better that spending the day making zip files.

MyBase.Update()  calls the Update method on the base class, in this case, System.Windows.Forms.Form.   I don't know how much you know about Object Oriented design, but VB.NET went very OO.  In VB6 you had objects, but VB.NET jumped into OO with both feet.   The Update and Close methods are on the base class of the Form. 

The first method updates the UI - it's a way to tell the program, I just made a change and I'd like the change (maybe progress bar advance) to be visible NOW.  If you don't call Update then what can happen is those updates get queued and displayed "later". So the goal of calling Update is to make the UI update smoothly. 

Close just closes the form, or window. I understood that you were building an app that unzipped some things and then just closes when it's done. That's done by the call to Close.


Errors

If you get an error like "'Read' is not a member of 'String'.", on a line that includes a sequence like

    ZipFile.Read(zipfile)

.. I think the problem here is one of naming confusion. I'm not a VB person, no expert in VB, but I think VB may be NOT case sensitive, in other words zipfile is the same as ZipFile, in the program. Now zipfile is the name used to hold the string, the name of the file, while ZipFile is the name of the class. So if you rename the string to, say, zipfileName, you should avoid this problem.

    Me.label1.Text = ("Exception: " & ex1)

Change this to

    Me.label1.Text = ("Exception: " & ex1.ToString())

(The reason you're having these problems is that I converted a C# program to VB.NET, using a conversion program. Like I said, I'm not a vb.net expert. With the automatic conversion, you get these kinds of problems)

Rather than go through all these problems, how about I just get my converted code to actually compile before I send it to you?  The following code compiles successfully, and works.

'' qunzip.vb
'' ------------------------------------------------------------------
''
'' A simple app that unzips a file, showing a progress bar. 
'' It is both a console app, and a winforms app.  
'' 
'' built on host: DINOCH-2
'' Created Thu Aug 06 15:34:17 2009
''
'' last saved: 
'' Time-stamp: <2009-August-13 11:25:08>
'' ------------------------------------------------------------------
''
'' Copyright (c) 2009 by Dino Chiesa
'' All rights reserved!
''
'' Licensed under the Microsoft Public License.
'' see http://www.opensource.org/licenses/ms-pl.html
''
'' ------------------------------------------------------------------

Imports System
Imports System.Reflection
Imports System.Windows.Forms
Imports Ionic.Zip


'' to allow fast ngen
<assembly: AssemblyTitle("Qunzip.cs")>
<assembly: AssemblyDescription("quick winforms unzip tool")>
<assembly: AssemblyConfiguration("")>
<assembly: AssemblyCompany("Dino Chiesa")>
<assembly: AssemblyProduct("Tools")>
<assembly: AssemblyCopyright("Copyright © Dino Chiesa 2009")>
<assembly: AssemblyTrademark("")>
<assembly: AssemblyCulture("")>
<assembly: AssemblyVersion("1.1.1.1")>


Namespace Ionic.ToolsAndTests.VB

    '' see example     :
    '' http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/875952fc-cd2c-4e74-9cf2-d38910bde613

    Friend Class QuickUnzip
        ' Methods
        <System.Runtime.InteropServices.DllImport("kernel32.dll")> _
        Private Shared Function AllocConsole() As Boolean
        End Function

        <System.Runtime.InteropServices.DllImport("kernel32.dll")> _
        Private Shared Function AttachConsole(ByVal pid As Integer) As Boolean
        End Function

        <STAThread> _
        Public Shared Sub Main(ByVal args As String())
            If Not QuickUnzip.AttachConsole(-1) Then
                QuickUnzip.AllocConsole
            End If
            If (args.Length <> 1) Then
                QuickUnzip.Usage(args)
            Else
                Application.EnableVisualStyles
                Application.SetCompatibleTextRenderingDefault(False)
                Dim f As New QuickUnzipForm(args(0))
                Application.Run(f)
            End If
        End Sub

        Private Shared Sub Usage(ByVal args As String())
            Console.WriteLine("QuickUnzip.  Usage:  QuickUnzip <zipfile>")
        End Sub

    End Class



    Public Class QuickUnzipForm
        Inherits Form
        ' Methods
        Public Sub New()
            Me.components = Nothing
            Me.InitializeComponent
        End Sub

        Public Sub New(ByVal zipfile As String)
            Me.New()
            Me.zipfileName = zipfile
        End Sub

        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If (disposing AndAlso (Not Me.components Is Nothing)) Then
                Me.components.Dispose
            End If
            MyBase.Dispose(disposing)
        End Sub

        Private Sub FixTitle()
            Me.Text = String.Format("Quick Unzip {0}", Me.zipfileName)
        End Sub

        Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container
            Me.label1 = New Label
            Me.progressBar1 = New ProgressBar
            MyBase.SuspendLayout
            Me.label1.AutoSize = True
            Me.label1.Location = New System.Drawing.Point(12, 12)
            Me.label1.Name = "label1"
            Me.label1.Size = New System.Drawing.Size(50, 13)
            Me.label1.TabIndex = 2
            Me.label1.Text = "Progress"
            Me.progressBar1.Anchor = (AnchorStyles.Right Or (AnchorStyles.Left Or AnchorStyles.Top))
            Me.progressBar1.Location = New System.Drawing.Point(15, 50)
            Me.progressBar1.Name = "progressBar1"
            Me.progressBar1.Size = New System.Drawing.Size(310, &H12)
            Me.progressBar1.Step = 1
            Me.progressBar1.TabIndex = 7
            MyBase.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!)
            MyBase.AutoScaleMode = AutoScaleMode.Font
            MyBase.ClientSize = New System.Drawing.Size(340, 140)
            MyBase.Controls.Add(Me.label1)
            MyBase.Controls.Add(Me.progressBar1)
            MyBase.Name = "QuickUnzipForm"
            Me.Text = "QuickUnzip"
            AddHandler MyBase.Load, New EventHandler(AddressOf Me.QuickUnzipForm_Load)
            AddHandler MyBase.Shown, New EventHandler(AddressOf Me.QuickUnzipForm_Shown)
            MyBase.ResumeLayout(False)
            MyBase.PerformLayout
        End Sub

        Public Sub OnTimerEvent(ByVal source As Object, ByVal e As EventArgs)
            MyBase.Close
        End Sub

        Private Sub QuickUnzipForm_Load(ByVal sender As Object, ByVal e As EventArgs)
            Me.FixTitle
        End Sub

        Private Sub QuickUnzipForm_Shown(ByVal sender As Object, ByVal e As EventArgs)
            Try 
                Using zip As ZipFile = ZipFile.Read(Me.zipfileName)
                    Me.progressBar1.Maximum = zip.Entries.Count
                    Dim entry As ZipEntry
                    For Each entry In zip
                        Me.label1.Text = entry.FileName
                        MyBase.Update
                        entry.Extract("quickunzip", ExtractExistingFileAction.OverwriteSilently)
                        Me.progressBar1.PerformStep
                        MyBase.Update
                        System.Threading.Thread.Sleep(50)
                    Next
                End Using
            Catch ex1 As Exception
                Me.label1.Text = ("Exception: " & ex1.ToString)
            End Try
            Dim timer1 As New System.Timers.Timer(1000)
            timer1.Enabled = True
            timer1.AutoReset = False
            AddHandler timer1.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf Me.OnTimerEvent)
        End Sub


        ' Fields
        Private zipfileName As String
        Private components As System.ComponentModel.IContainer
        Private label1 As Label
        Private progressBar1 As ProgressBar
    End Class



End Namespace

I suggest you get yourself a book, like a VB.NET for VB developers book.  You might be able to find some help on http://msdn.microsoft.com/en-us/vbasic/default.aspx.  Check out the "Getting Started" link on the left-hand-side.

Good luck!

 

Aug 13, 2009 at 5:42 PM

thanks alot thats what i needed.

this is what i got working for everyone or anyone that is following this topic.

i made a new module my main form is named form1 (you need to change this to whatever your form name is in the module wherever it says form1 i underlined bold and turned red all the spots)

name the module SimpleUnzip.vb

past this code in the module

Imports Ionic.Zip

Module SimpleUnzip
Public Sub Unzip(ByVal ZipToUnpack As String, ByVal DirectoryToExstractTo As String)
Try Using zip As ZipFile = ZipFile.Read(ZipToUnpack)
Form1.ProgressBar1.Maximum = zip.Entries.Count Dim entry As ZipEntry
For Each entry In zip
Form1.Label1.Text = entry.FileName
entry.Extract(DirectoryToExstractTo, ExtractExistingFileAction.OverwriteSilently)
Form1.ProgressBar1.Value = Form1.ProgressBar1.Value + 1
' sleep because it's too fast otherwise. System.Threading.Thread.Sleep(50) Next
Form1.ProgressBar1.Value = 0
Form1.Label1.Text = "Done" End Using Catch ex1 As Exception
Form1.Label1.Text = ("Exception: " & ex1.ToString())
End Try End Sub End Module

that's it.. call it in your forum with

Unzip("C1P3SML.zip", "C1P3SML")

or

Unzip(unzip file, dir to unzip to)

 

that's it so simple i cant beleave i needed so much help lol.. thanks alot Cheeso your the man.

Coordinator
Aug 13, 2009 at 10:01 PM

Glad it worked for you.

here is the full example (with multi-threading):

http://dotnetzip.codeplex.com/Wiki/View.aspx?title=WinForms-QuickUnzip-VB