TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nikunj Satasiya
184
10k
3.7m
Compress File Using Ionic.ZIP with Progress Bar Win forms C#
Jun 5 2019 5:45 AM
Hey Friends, in my company one of my friend finding a solution for one of the issues regarding the zip file. so I post this question with detailed information on behalf of him, he also posted same questions in other developers community such as StackOverflow and etc but still didn't get expected solution, please write any solution for this problem.
I'm preparing an application that creates a zip file for a given directory.
I want the following things to display while creating a zip.
Estimated time for completing that zip (Elapsed Time and Time left)
The percentage for completion of Zipping
Here is my written code:
private
void
CreateZip(
string
FilePath)
{
using
(ZipFile zip =
new
ZipFile())
{
zip.AddProgress += Zip_AddProgress;
zip.SaveProgress += Zip_SaveProgress;
zip.CompressionMethod = Ionic.Zip.CompressionMethod.Deflate;
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
if
(!
string
.IsNullOrEmpty(FilePath))
{
zip.AddDirectory(FilePath,
new
DirectoryInfo(FilePath).Name);
}
var d= zip;
if
(File.Exists(txtDest.Text))
{
File.Delete(txtDest.Text);
}
zip.Save(txtDest.Text);
}
}
private
void
Zip_SaveProgress(
object
sender, SaveProgressEventArgs e)
{
if
(e.EventType == ZipProgressEventType.Saving_Started)
lblFileName.Text =
"Proccess Started Successfully"
;
if
(e.EventType == ZipProgressEventType.Saving_AfterSaveTempArchive)
lblFileName.Text =
"Proccess Completed Successfully"
;
if
(e.BytesTransferred > 0 && e.TotalBytesToTransfer > 0)
{
int
progress = (
int
)Math.Floor((
decimal
)((e.BytesTransferred * 100) / e.TotalBytesToTransfer));
pbPerFile.Value = progress;
lblPercentagePerFile.Text = Convert.ToString(progress) +
"%"
;
lblFileName.Text =
"File Name: "
+ e.CurrentEntry.UncompressedSize;
Application.DoEvents();
}
if
(e.EntriesSaved > 0 && e.EntriesTotal > 0)
{
int
progress = (
int
)Math.Floor((
decimal
)((e.EntriesSaved * 100) / e.EntriesTotal));
pbTotalFile.Value = progress;
Application.DoEvents();
lblTotal.Text = Convert.ToString(progress) +
"%"
;
}
}
The first progress bar works on the size of the file because of
e.BytesTransferred
and
e.TotalBytesToTransfer
is return size in Bytes.
But, EntriesSaved and
e.EntriesTotal
will return the length of the saved entries and a total number of entries that we have added.
So I want that second Progress Bar to work based on the size of the Entire Selected files and Compressed File.
Your efforts will be appreciated.
Thanks...
Reply
Answers (
1
)
Heap or Stack ?
Communication between two forms