Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET ZIP
For some reason when I try to unpack a zip it does not update the progress bar any help would be welcomed.
 
Imports Ionic.Zip
Imports System.Threading
 
Public Class Form1
 
    Private Property CurrentCount As Integer
    Private Property TotalCount As Integer
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        BackgroundWorker1.RunWorkerAsync()
    End Sub
 
    Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
    End Sub
 
    Private Delegate Sub SetStatusTextInvoker(ByVal Text As String)
    Private Sub SetStatusText(ByVal Text As String)
        If Me.InvokeRequired Then
            Me.Invoke(New SetStatusTextInvoker(AddressOf SetStatusText), Text)
        Else
            Label1.Text = Text
        End If
    End Sub
 
    Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim TotalSize As Long
        Dim ZipToUnpack As String = "C:\temp\1.zip"
        Dim extractDir As String = "C:\temp\extract"
 
        Try
            Using zip As ZipFile = ZipFile.Read(ZipToUnpack)
                AddHandler (zip.ExtractProgress), New EventHandler(Of ExtractProgressEventArgs)(AddressOf Zip_ExtractProgress)
 
                For Each Entry As ZipEntry In zip.Entries
                    TotalSize += Entry.UncompressedSize
                Next
                For Each Entry As ZipEntry In zip.Entries
                    Entry.Extract(extractDir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
                Next
            End Using
        Catch EX As Exception
            MessageBox.Show(EX.Message)
        End Try
    End Sub
 
    Private Sub Zip_ExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
        If BackgroundWorker1.CancellationPending Then
            e.Cancel = True 'If we press the stop button, reset the variables we used for extracting, then invoke Cancel. RunWorkerCompleted will be called.
        End If
 
        Select Case e.EventType
            Case ZipProgressEventType.Extracting_EntryBytesWritten
 
                Dim Entry As Integer
                Dim CurrentCount As Integer = Entry
    
                BackgroundWorker1.ReportProgress(CInt(Int((100 * (CurrentCount / TotalCount)))))
        End Select
    End Sub
End Class
Posted 1-Jan-13 9:20am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have you set a breakpoint to see if it's being called ? If it is, you could try Application.DoEvents, if the issue is just that a paint event is needed.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this code and see if is helping you, i use only one ProgressBar.
 
Imports Ionic.Zip
Imports System.Threading
Imports System.IO
 

Public Class Form1
 
    Private CurrentCount As Integer = 0
    Private TotalCount As Long = 0, Total As Long = 0, LastVal As Long = 0, Sum As Long = 0
 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        BackgroundWorker1.RunWorkerAsync()
    End Sub
 
    Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        ProgressBar1.Maximum = CInt(TotalCount)
        ProgressBar1.Value = e.ProgressPercentage
    End Sub
 
    Private Delegate Sub SetStatusTextInvoker(ByVal Text As String)
    Private Sub SetStatusText(ByVal Text As String)
        System.Threading.Thread.Sleep(6)
        If Me.InvokeRequired Then
            Me.Invoke(New SetStatusTextInvoker(AddressOf SetStatusText), Text)
        Else
            Label1.Text = Text
        End If
    End Sub
 
    Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        ExtractZip("C:\test\test.zip", "C:\test\extract\")
    End Sub
 
    Public Sub ExtractZip(ByVal szFileZip As String, ByVal ExtractTo As String)
 
        ' This will delete temp file when you cancel the extraction.
        Dim szGetFiles As Collections.ObjectModel.ReadOnlyCollection(Of String)
        Dim FilePath As String
        szGetFiles = My.Computer.FileSystem.GetFiles("C:\test\", FileIO.SearchOption.SearchAllSubDirectories, "*.tmp")
        For Each FilePath In szGetFiles
            File.Delete(FilePath)
        Next
        Try
            CurrentCount = 0
            Using MyZip As ZipFile = ZipFile.Read(szFileZip)
                AddHandler (MyZip.ExtractProgress), New EventHandler(Of ExtractProgressEventArgs)(AddressOf Zip_ExtractProgress)
                For Each Entry As ZipEntry In MyZip
                    CurrentCount += 1
                    TotalCount += Entry.UncompressedSize
                Next Entry
                MyZip.ExtractAll(ExtractTo, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
            End Using
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub
 
    Private Sub Zip_ExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
        If BackgroundWorker1.CancellationPending Then
            e.Cancel = True 'If we press the stop button, reset the variables we used for extracting, then invoke Cancel. RunWorkerCompleted will be called.
        End If
        System.Windows.Forms.Application.DoEvents()
        If Total <> e.TotalBytesToTransfer Then
            SetStatusText(e.CurrentEntry.FileName)
            Sum += Total - LastVal + e.BytesTransferred
            Total = e.TotalBytesToTransfer
        Else
            Sum += e.BytesTransferred - LastVal
        End If
        LastVal = e.BytesTransferred
        BackgroundWorker1.ReportProgress(CInt((Sum)))
    End Sub
 
    Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        ProgressBar1.Value = 0
        SetStatusText("Completed")
    End Sub
End Class
 
  Permalink  
v2
Comments
Blutfaust at 9-Jul-14 15:10pm
   
So you think the TO is still waiting for a solution? After 1,5 years?
florin2020 at 10-Jul-14 5:17am
   
@Blutfaust you right, this is my first answer here, maybe this solution for him is not important anymore, but maybe for other people that searching for this solution is important.
Sorry my bad english.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 406
1 /\jmot 180
2 Suraj Sahoo | Coding Passion 170
3 BillWoodruff 159
4 Afzaal Ahmad Zeeshan 154
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 9 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100