0

I am using the paid version of Xceed.Zip.QuickZip.Zip utility in my application to compress a folder that contains files and directories. Here is the Xceed Zip command that I am using

Xceed.Zip.Licenser.LicenseKey = XceedZipKey;
Xceed.Zip.QuickZip.Zip(ZipFilePath, true, true, true, filesToZip);

ZipFilePath is the name of thr final zip including the path where the zip will be created. So it is like D:\MyData/MyZip.zip.

And, filesToZip is like this D:\MyDataToZip\Versions\\*.*.

So when the zip is created, I see a MyDataToZip folder, which contains Versions folder and then everything that is inside the Version folder.

But I want the zip to not contain the MyDataToZip & Versions folder. It should start from Versions folder. How can I achieve that?

Please note that my application is built on .Net 4.0, so I can't use System.IO.Compression.

halfer
  • 19,824
  • 17
  • 99
  • 186
WAQ
  • 2,556
  • 6
  • 45
  • 86

2 Answers2

1

Use the Xceed FileSystem API in order to preserve the file paths from the target folder down.

public void ZipFolder(string zipFilePath, string folderPath, bool recursive, bool replaceExistingFiles, params object[] filters)
{
    AbstractFile zipFile = new DiskFile(zipFilePath);
    ZipArchive zip = new ZipArchive(zipFile);

    using (AutoBatchUpdate batch = new AutoBatchUpdate(zip))
    {
        AbstractFolder sourceFolder = new DiskFolder(folderPath);
        sourceFolder.CopyFilesTo(zip, recursive, replaceExistingFiles, filters);
    }
}
Mathew Leger
  • 1,613
  • 17
  • 22
0

you need to use

Xceed.Zip.QuickZip.Zip(ZipFilePath, true, true, false, filesToZip);

as the 4th parameter is:

preservePaths Boolean value indicating if the directory structure should be preserved in the zip file.

REF: Zip(String,Boolean,Boolean,Boolean,String[]) Method

Bolu
  • 8,696
  • 4
  • 38
  • 70
  • 1
    Setting preservePaths to false puts everything on the Main. creates no subfolders at all. I want all directories/sub directories to be preserved after \*.* but I dont want the directories which appear before that. – WAQ Sep 30 '14 at 11:49
  • 1
    @WQad, Then you probably need to use other method like [`CopyFilesTo`](http://doc.xceedsoft.com/products/XceedWfWorkflow/Xceed.FileSystem~Xceed.FileSystem.AbstractFolder~CopyFilesTo(AbstractFolder,Boolean,Boolean,Object[]).html). [See this for an example](http://xceed.com/CS/forums/thread/32065.aspx) – Bolu Sep 30 '14 at 13:07