By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

DotNetZip extraction progress reporting\event help

P: 6
Hi All.

Could someone give me some advice on reporting progress from a zip extraction using the DotNetZip Library?

I'm not an experienced programmer so having trouble understanding this.

I've created an event to report the progress (ProgressEventHandler) but the progress bar is still not updating.

The ExtractProgressEventArgs class TotalBytesToTransfer and BytesTransferred which I believe I need to use to set the maximum and increment value of the progress bar.

I'm trying to report the whole extraction (Resulting in a smooth progress bar for the whole unzip) rather than a steped progress bar per file as the examples given on the DotNetZip site.

So far I have:

Expand|Select|Wrap|Line Numbers
  1. Imports Ionic.Zip
  2. Imports System.Threading
  3. Imports System.Reflection
  4.  
  5. Public Class Form1
  6.  
  7.     Dim zipfileName As String = "C:\Test\test123.zip"
  8.     Dim extractDirectory As String = "C:\Test\"
  9.     Private Delegate Sub UpdateProgressBarInvoker(ByVal Value As Integer)
  10.  
  11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.     End Sub
  13.  
  14.     Private Sub Unzip()
  15.         Dim args(2) As String
  16.         args(0) = Me.zipfileName
  17.         args(1) = Me.extractDirectory
  18.         Dim t = New Thread(AddressOf Me.UnzipFile)
  19.         t.Start(args)
  20.         While Me.BackgroundWorker1.IsBusy
  21.             ' Keep UI messages moving, so the form remains 
  22.             ' responsive during the asynchronous operation.
  23.             Application.DoEvents()
  24.         End While
  25.     End Sub
  26.  
  27.     Private Sub UnzipFile(ByVal args As String())
  28.         Using zip As ZipFile = ZipFile.Read(args(0))
  29.             AddHandler zip.ExtractProgress, AddressOf ProgressEventHandler
  30.  
  31.             Dim entry As ZipEntry
  32.             For Each entry In zip
  33.                 entry.Extract(args(1), ExtractExistingFileAction.OverwriteSilently)
  34.             Next
  35.         End Using
  36.     End Sub
  37.  
  38.     Private Sub ProgressEventHandler(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
  39.         SetControlPropertyValue(ProgressBar1, "Maximum", e.TotalBytesToTransfer)
  40.         SetControlPropertyValue(ProgressBar1, "value", e.BytesTransferred)
  41.     End Sub
  42.  
  43.  
  44.  
  45.  
  46.     Delegate Sub SetControlValueCallback(ByVal oControl As Control, ByVal propName As String, ByVal propValue As Object)
  47.  
  48.     Private Sub SetControlPropertyValue(ByVal oControl As Control, ByVal propName As String, ByVal propValue As Object)
  49.         If (oControl.InvokeRequired) Then
  50.  
  51.             Dim d As New SetControlValueCallback(AddressOf SetControlPropertyValue)
  52.             oControl.Invoke(d, New Object() {oControl, propName, propValue})
  53.         Else
  54.             Dim t As Type = oControl.[GetType]()
  55.             Dim props As PropertyInfo() = t.GetProperties()
  56.             For Each p As PropertyInfo In props
  57.                 If p.Name.ToUpper() = propName.ToUpper() Then
  58.                     p.SetValue(oControl, propValue, Nothing)
  59.                 End If
  60.             Next
  61.         End If
  62.     End Sub
  63.  
  64.     Private Sub BtnUnzip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUnzip.Click
  65.         Unzip()
  66.     End Sub
  67.  
  68. End Class
  69.  

I'm using examples from here(Half way down):
http://dotnetzip.codeplex.com/wikipage?title=VB-Examples&referringTitle=Examples

Thank you in advance.
Jun 16 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.