How can I compress a folder with its all files and folders with a progressBar c#

Jul 30, 2012 at 9:53 PM
Edited Jul 30, 2012 at 9:54 PM

How can I compress a folder with its all files and folders with a progressBar c#.

In all the examples I was looking for I have not found anything similar To what I'm looking for.

 

            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory("d:\\1");
                zip.Comment = "TEST TEST";
                zip.Save("d:\\2\\test.zip");

            }

my Code How can I add to this code a progress Bar in c#. Or Other code for compressing a folder.

Apr 10, 2014 at 11:38 AM
Try this
private async void ZipIt(string src, string dest)
{
    await Task.Run(() =>
    {
        using (var zipFile = new ZipFile())
        {
            // add content to zip here 
            zipFile.AddDirectory(src);
            zipFile.SaveProgress +=
                (o, args) =>
                {
                    var percentage = (int)(1.0d / args.TotalBytesToTransfer * args.BytesTransferred * 100.0d);
                    // report your progress
                    pbCurrentFile.Dispatcher.Invoke(
                        System.Windows.Threading.DispatcherPriority.Normal,
                        new Action(
                        delegate()
                        {

                            pbCurrentFile.Value = percentage;
                        }
                        ));
                };
            zipFile.Save(dest);
        }
    });
}