Creating a zip file with a relative path

Nov 28, 2007 at 11:03 AM

Problem

I need to be able to create a zip file of FolderA that contains files and folders. The top level entry in the zip file needs to be FolderA but instead it is the root folder of FolderA.

Example

For example, to zip a folder with a path c:\temp\build

When opening the zip the root is temp instead of what I wanted: build

Is there any functionality within the library that can allow me do this?

Kind regards,

JW
Coordinator
Dec 5, 2007 at 3:03 AM
Yes, you can do what you want. Did you try this:

        System.IO.Directory.SetCurrentDirectory("c:\\temp");
        zip.AddItem("build");
        zip.Save(); 
Dec 5, 2007 at 10:19 AM
That's great.

Many thanks.

JW
Dec 17, 2007 at 3:55 PM
This way will include the tail folder name of the current directory name, e.g "D:\fldr\abc" then in the zip file the root dir is "abc". Maybe this is not your expected result.

If use the overload methods AddXXX(fileOrDirectory, directoryInArchive) can resolve the issue.


Tao