troubleshooting Question

Compress Directory + SubFolders using ZipOutputStream

Avatar of nikez2k4
nikez2k4Flag for United Kingdom of Great Britain and Northern Ireland asked on
12 Comments1 Solution1033 ViewsLast Modified:
Hi.  I'm trying to compress a folder (and it's subdirectories).  I've adapted code I've found on the net which zip's up the files within the folder specified, but not the sub-folders (ie, the entire contents).

Here's the code:
string[] filenames = Directory.GetFiles(str_vledatasource.Text);
using (ZipOutputStream s = new ZipOutputStream(File.Create(str_vledatadestination.Text+"\\VLE Backup ("+ strTimeStamp.ToString()+").zip")))

                    s.SetLevel(9); // 0-9, 9 being the highest compression
                    byte[] buffer = new byte[4096];

                    foreach (string file in filenames)
                        ZipEntry entry = new
                        entry.DateTime = DateTime.Now;
                        using (FileStream fs = File.OpenRead(file))


                            int sourceBytes;

                               sourceBytes = fs.Read(buffer, 0, buffer.Length);
                               s.Write(buffer, 0, sourceBytes);

                            while (sourceBytes > 0);




Can anyone help me finish this off, please?
str_vledatasource.Text is the string for the location
str_vledatadestination.Text is the string for the output/destination of the zip.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros