Jul 10, 2012 at 2:14 PM
Edited Jul 10, 2012 at 2:33 PM
|
Hi All,
I was able to get this to work after googling for a few days. The only challenge is that the progress bar does not get update. Can anyone help with it.
I tried the following in the invoke section to no avail. ANY help will be greatly appreciated.
' Me.ProgressBar1.Value = 100 * e.BytesTransferred / e.TotalBytesToTransfer
' Me.ProgressBar1.Value = 100 * TranferTotal / TotalSize
' lblResults.Text = CStr(100 * (e.BytesTransferred / e.TotalBytesToTransfer).ToString("#,##0.00")) & "% Complete"
'ProgressBar1.Value =
Convert.ToInt32(100 * e.BytesTransferred / e.TotalBytesToTransfer)
ImportsIonic.Zip
Imports System.Threading
Public
Class Form1
Private
Sub Button1_Click(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
End
Sub
Private
Sub BackgroundWorker1_DoWork(sender
As System.Object, e
As System.ComponentModel.DoWorkEventArgs)
Handles BackgroundWorker1.DoWork
lblResults.Text =
Nothing
DotNetZip_Extract_With_ProgressBar()
End
Sub
Private
Delegate Sub
ZipProgress(ByVal e
As ExtractProgressEventArgs)
Private
Delegate Sub
ExtractEntryProgress(ByVal e
As ExtractProgressEventArgs)
Private
Sub zip_ExtractProgress(ByVal sender
As Object,
ByVal e As ExtractProgressEventArgs)
StepEntryProgress(e)
End
Sub
Private
Sub StepEntryProgress(ByVal e
As ExtractProgressEventArgs)
'Dim TranferTotal As Integer
' TranferTotal = TranferTotal + backup.UncompressedSize
' TranferTotal = e.BytesTransferred + TranferTotal
If Me.ProgressBar1.InvokeRequired
Then
ProgressBar1.Invoke(New
ExtractEntryProgress(AddressOf
Me.StepEntryProgress), New
Object() {e})
Else
If ProgressBar1.Maximum = 100
Then
ProgressBar1.Value =
Convert.ToInt32(100 * e.BytesTransferred / e.TotalBytesToTransfer)
' Me.ProgressBar1.Value = 100 * e.BytesTransferred / e.TotalBytesToTransfer
' lblResults.Text = CStr(100 * (e.BytesTransferred / e.TotalBytesToTransfer).ToString("#,##0.00")) & "% Complete"
' Me.ProgressBar1.Value = 100 * TranferTotal / TotalSize
Else
lblResults.Text =
"Done"
End If
End If
End
Sub
Sub DotNetZip_Extract_With_ProgressBar()
Dim TotalSize = 0
Dim TranferTotal As
Integer = 0
Dim ZipToUnpack As
String = "C:\Temp\1.zip"
Dim extractDir As
String = "C:\Temp\Extract"
Using zip As ZipFile =
ZipFile.Read(ZipToUnpack)
AddHandler (zip.ExtractProgress),
New EventHandler(Of
ExtractProgressEventArgs)(AddressOf
Me.zip_ExtractProgress)
For Each backup
In zip
TotalSize = backup.UncompressedSize + TotalSize
Next
For Each backup
In zip
backup.Extract(extractDir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
Next
End Using
End Sub
End
Class
|