1

I am not sure if its a gap in my understanding. I have to zip a folder which sits on a server in the same network. Suppose I have a folder WebSite on the D drive of ABC machine on XYZ domain (same network as my machine). I use the following code to zip it

        using (ZipFile myZip = new ZipFile())
        {
            myZip.AddSelectedFiles("*.*", @"\\ABC.XYZ.com\d$\WebSite\", true);

            myZip.Save(@"\\ABC.XYZ.com\d$\Test.zip");
        }

Using this code I get an archive in the D drive of the server ABC but, the structure of the zip would look like this.

Test.zip -> ABC.XYZ.com -> d$ -> Website

Is there some alternative way to get the Zip file like Test.zip -> Website, while on a network path.

Niranjan
  • 813
  • 2
  • 12
  • 33
  • possible duplicate of http://stackoverflow.com/questions/4125607/dotnetzip-add-files-without-creating-folders – bhathiya-perera Nov 15 '13 at 05:22
  • Nope, it is not a duplicate. It is not about storing files without path, but storing files in a different ZIP root directory, if i understood correctly. –  Nov 15 '13 at 05:26
  • i had tried AddFile() enumerating each file.. but it didn't work for me.. as within the Website folder I have subfolders which contains the same filenames.. with AddFile it would throw a dictionary error... – Niranjan Nov 15 '13 at 05:29

1 Answers1

3

Use the ZipFile.AddDirectory method:

using (ZipFile myZip = new ZipFile())
{
    myZip.AddDirectory(@"\\ABC.XYZ.com\d$\WebSite\", "WebSite");
    myZip.Save(@"\\ABC.XYZ.com\d$\Test.zip");
}