Creating a zip saves entire pathname?

May 15, 2008 at 3:34 PM

Someone wrote:
I would like to create a zip with some files, and a couple of folders and sub folders, but when I do this, it is copying the entire directory breakdown. Only the files in these folders are copied, but it includes the entire directory location in the zip... How can I fix this?

Here is the code I am using:

  using (ZipFile zip = new ZipFile(DatabaseCBFilePathTB1.Text + @"\"))
    zip.AddFile(Environment.CurrentDirectory + @"\DB.accdb");
    zip.AddDirectory(Environment.CurrentDirectory + @"\Files");

Any help and information is greatly appreciated.

Thanks Again,

May 15, 2008 at 3:38 PM

Couple ways to do this

  1. There's an override on the AddFile() method that allows you to explicitly specify the directory within the zip archive, to use for that entry.  Likewise for AddDirectory().  If you want a flat directory space, then you can specify "" (empty string, not null/nothing) for that parameter.  Check the doc.
  2. change to the directory that contains the file using 


     , then call AddFile() with an unqualified pathname.