int fileCount = 0;
long totalSize = 0, total = 0, lastVal=0,sum=0;
public void ReadAndExtract(string openPath, string savePath)
{
try
{
fileCount = 0;
Ionic.Zip.ZipFile myZip = new Ionic.Zip.ZipFile();
myZip = Ionic.Zip.ZipFile.Read(openPath);
foreach (var entry in myZip)
{
fileCount++;
totalSize += entry.UncompressedSize;
}
progressBar1.Maximum = (Int32)totalSize;
myZip.ExtractProgress += new EventHandler<ionic.zip.extractprogresseventargs>(myZip_ExtractProgress);
myZip.ExtractAll(savePath,Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
void myZip_ExtractProgress(object sender, Ionic.Zip.ExtractProgressEventArgs e)
{
System.Windows.Forms.Application.DoEvents();
if (total != e.TotalBytesToTransfer)
{
sum += total - lastVal + e.BytesTransferred;
total = e.TotalBytesToTransfer;
}
else
sum += e.BytesTransferred - lastVal;
lastVal = e.BytesTransferred;
progressBar1.Value = (Int32)sum;
}
</ionic.zip.extractprogresseventargs>