0

I need to get the % while compressing a zip file using C# with System.IO.Compression. I have this code:

if (isDirectory) {
                    Invoke(new RefreshConsoleEncryptionDel(RefreshConsoleEncryption), "[+]Wait, compressing folder...");
                    ZipFile.CreateFromDirectory(FileName, FileName + "_DirEnc.zip");
                    Invoke(new RefreshProcessBar1Del(RefreshProcessBar1), 100);
                    Invoke(new RefreshConsoleEncryptionDel(RefreshConsoleEncryption), "[✓]COMPLETED");
                    Invoke(new RefreshConsoleEncryptionDel(RefreshConsoleEncryption), "[K]Starting encrypting file...");

                    byte[] BytePasswordArray = IsFile ? File.ReadAllBytes(Password) : Encoding.UTF8.GetBytes(Password); // We create the array who will contain all bytes of password, depending if its an file password or just a string; 
                                                                                                                        // A simple ternary condition, who checks if is file or string password 
                    FileEncryptProcess(5000000, FileName + "_DirEnc.zip", BytePasswordArray); // We call the function to encrypt the file. 
                                                                              // If all goes allright we continue, else this thread will be aborted and we cant continue to next line. 
                    Thread.CurrentThread.Abort();// If we can continue, then all will be allright and we close this thread succesfully.


                }

And I need to update the ProgressBar1 with the percentage by which the Zip compression goes by. It is possible?

KAoTI
  • 37
  • 6
  • Typically progress is reported back via events or a callback method. I'm not familiar with System.IO.Compression, but a quick glance through the documentation didn't seem to show any events or methods that take a callback method. So possibly there's exposed method of getting progress on this particular library. – mason Sep 19 '19 at 18:24
  • Thx Mason, but i finally found a solution! ive used this thread: https://stackoverflow.com/questions/42430559/progress-bar-not-available-for-zipfile-how-to-give-feedback-when-program-seems – KAoTI Sep 19 '19 at 18:59
  • Does this answer your question? [Progress Bar not available for zipfile? How to give feedback when program seems to hang](https://stackoverflow.com/questions/42430559/progress-bar-not-available-for-zipfile-how-to-give-feedback-when-program-seems) – StayOnTarget Aug 17 '22 at 12:00

0 Answers0