This project is read-only.

Extract files without saved path

May 24, 2010 at 4:24 PM
Edited May 24, 2010 at 4:30 PM

Hello, can I extract my zip files into another directory wich is not the same as I saved it ?

This is the directory structure saved into


--> dir A
   --> sub dir A
      --> file.txt

I want save file.txt into this sample directories structure :
   --> file.txt
If use e.Extract(targetDir, ExtractExistingFileAction.OverwriteSilently)
passing directory_C as targetDir the final result is :

  --> dir A 
     --> sub dir A 
        --> file.txt 

It's wrong for my use. Can you help me ?

Many Thank's
May 24, 2010 at 4:56 PM

yes. Rename the entry before calling Extract.

e.FileName = "directory_C\file.txt";


May 25, 2010 at 9:20 AM

Thank you for your reply but giving an error :


 foreach (ZipEntry e in zip)

                        FileInfo f = new FileInfo(e.FileName);
                        e.FileName = Path.Combine(targetDir, f.Name);

                        e.Extract(targetDir, ExtractExistingFileAction.OverwriteSilently);
                        logger.Trace("File {0} successfull unzipped on {1}", fileZipName, targetDir);

If I modify the filename into zip collection I have this error:
failed: System.ApplicationException : Collection was modified; enumeration operation may not execute.

Any other help ?

Bye, Claudio


May 26, 2010 at 8:54 AM

I read many many post ... :o(

there is same issue on :

Aug 2009

Feb 2009


May 26, 2010 at 11:26 AM

I need the required feature.

I can't use Rename the entry before calling Extract. because it throw an exception "collection was modified".

I switched now on

Simply settings false to PreserveDirectoryStructure flag I obtained my result correct.

Than you all, bye


May 26, 2010 at 12:35 PM
Edited May 26, 2010 at 12:35 PM
Instead of foreach (ZipEntry e in zip) Try foreach (ZipEntry e in zip.EntriesSorted) This is what I used as a workaround and it works great. Didn't need to change any other line of code.
May 26, 2010 at 3:58 PM


it run perfectly,

thank you very mutch.