dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] DotNetZip - Show Save Progress

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2010
    Posts
    56

    Resolved [RESOLVED] DotNetZip - Show Save Progress

    Hello, everyone! I'm using the third-party class called DotNetZip to create zip files of directories in my application, and no matter what I do, it seems like I can't get the progress of the compression process. Here's my code:

    HTML Code:
    public void CompressDir()
            {
                DirSize = 0;  
    
                // Create and initialize a new Zip file
                using (ZipFile zip = new ZipFile())
                {
                    // Read the progress of the saving
                    zip.SaveProgress += new EventHandler<SaveProgressEventArgs>(zip_SaveProgress);
    
                    // Add the directory to the zip file
                    zip.AddDirectory(Dir);
    
                    // Set the Zip file's compression level to best
                    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                    
                    // Save the Zip file
                    zip.Save(Dir + ".zip");
    
                    // Delete the original folder since we now have the zip file
                    Directory.Delete(Dir, true);
                }
            }
    
            private void zip_SaveProgress(object sender, SaveProgressEventArgs e)
            {
                // Add to the amount of bytes we've transferred so far
                DirSize += e.BytesTransferred;
    
                // Find out the percentage complete
                double ProgressPercent = (DirSize / TotalDirSize) * 100;
    
                ProgressPercent = Math.Round(ProgressPercent, 2); // Round the percentage to two decimal points
    
                DisplayText = Convert.ToString(ProgressPercent);
                context.Send((SendOrPostCallback)delegate { info.UpdateProgressTextBox(this, progress); }, null);
            }
    What I am doing to obtain the progress of the compression is dividing the total size of the directory (TotalDirSize) by the current amount of data transferred (DirSize). Then, I multiply this value by 100 to get a percentage, which I then display to the end user.

    Unfortunately, it seems that e.BytesTransferred almost always equals 0. I've displayed the value of it numerous times, and I'm not sure why it's stuck at zero.

    As a result, I tried a different approach to getting the progress of the compression. I tried using e.EntriesSaved and e.EntriesTotal. Before starting the Save process, I obtained the total number of entries in the zip file after the line, zip.AddDirectory(Dir);, and I got a value of 112.

    Then, I tried dividing 112 by e.EntriesSaved; however, the value would only come out to 0. I displayed the value of e.EntriesSaved, and it came out to 0, so that's why I was always getting 0&#37; as my progress completed. So, I decided to try e.EntriesTotal, but that ended up being 0 all the time as well.

    From the looks of it, it seems like DotNetZip's progress indications are flawed and are not complete; however, I could be wrong. Does anyone think he/she could help me out, please? Everything works fine except displaying the progress of the compression. I've been working on this for two days but still couldn't come up with something that works.

    EDIT: Figured it out. Thanks.
    Last edited by hydrakiller4000; Oct 27th, 2011 at 06:09 PM.

  2. #2
    New Member
    Join Date
    Apr 2014
    Posts
    1

    Re: [RESOLVED] DotNetZip - Show Save Progress

    Quote Originally Posted by hydrakiller4000 View Post
    Hello, everyone! I'm using the third-party class called DotNetZip to create zip files of directories in my application, and no matter what I do, it seems like I can't get the progress of the compression process. Here's my code:

    HTML Code:
    public void CompressDir()
            {
                DirSize = 0;  
    
                // Create and initialize a new Zip file
                using (ZipFile zip = new ZipFile())
                {
                    // Read the progress of the saving
                    zip.SaveProgress += new EventHandler<SaveProgressEventArgs>(zip_SaveProgress);
    
                    // Add the directory to the zip file
                    zip.AddDirectory(Dir);
    
                    // Set the Zip file's compression level to best
                    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                    
                    // Save the Zip file
                    zip.Save(Dir + ".zip");
    
                    // Delete the original folder since we now have the zip file
                    Directory.Delete(Dir, true);
                }
            }
    
            private void zip_SaveProgress(object sender, SaveProgressEventArgs e)
            {
                // Add to the amount of bytes we've transferred so far
                DirSize += e.BytesTransferred;
    
                // Find out the percentage complete
                double ProgressPercent = (DirSize / TotalDirSize) * 100;
    
                ProgressPercent = Math.Round(ProgressPercent, 2); // Round the percentage to two decimal points
    
                DisplayText = Convert.ToString(ProgressPercent);
                context.Send((SendOrPostCallback)delegate { info.UpdateProgressTextBox(this, progress); }, null);
            }
    What I am doing to obtain the progress of the compression is dividing the total size of the directory (TotalDirSize) by the current amount of data transferred (DirSize). Then, I multiply this value by 100 to get a percentage, which I then display to the end user.

    Unfortunately, it seems that e.BytesTransferred almost always equals 0. I've displayed the value of it numerous times, and I'm not sure why it's stuck at zero.

    As a result, I tried a different approach to getting the progress of the compression. I tried using e.EntriesSaved and e.EntriesTotal. Before starting the Save process, I obtained the total number of entries in the zip file after the line, zip.AddDirectory(Dir);, and I got a value of 112.

    Then, I tried dividing 112 by e.EntriesSaved; however, the value would only come out to 0. I displayed the value of e.EntriesSaved, and it came out to 0, so that's why I was always getting 0% as my progress completed. So, I decided to try e.EntriesTotal, but that ended up being 0 all the time as well.

    From the looks of it, it seems like DotNetZip's progress indications are flawed and are not complete; however, I could be wrong. Does anyone think he/she could help me out, please? Everything works fine except displaying the progress of the compression. I've been working on this for two days but still couldn't come up with something that works.

    EDIT: Figured it out. Thanks.

    How do you figured it out?

    LG Michael

  3. #3
    New Member
    Join Date
    Mar 2015
    Posts
    1

    Re: [RESOLVED] DotNetZip - Show Save Progress

    You need to base what you do in the update on e.EventType.

    More details at:
    https://www.whitebyte.info/programmi...-for-dotnetzip

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width