This project is read-only.

Can't extract into path, but subdir of that path is OK

Mar 17, 2011 at 12:59 AM
Edited Mar 17, 2011 at 2:00 AM

Hopefully, I'm missing something obvious.

...The most basic extract functionality does not work for me. The code below works in the case where the condition is false.

using (var archive = ZipFile.Read(tarFile)) { foreach (var file in archive) {...

var extractionFolder = file.FileName.EndsWith(".cs") ? dir : // if this is true, Extract just doesn't work
	Path.Combine(dir, "SubFolder"); // if this is true, it works fine
file.Extract(extractionFolder, ExtractExistingFileAction.OverwriteSilently);

* I found the file! It is extracting it! But it's using the PATH it was originally zipped up with c:\bla\user\appdata\temp and appending that to the folder I've given it.

The problem seems to be that the zipfile.FileName is being set as the 'full path' not just the filename when I archive it. So when I go to extract this particular file, it extracts out to the path it has in it's 'FileName' property, which is wrong

The other files work because they're being added using AddDirectory()... for some reason they don't retain the full path in their FileName property and the single file does


So I gather you are not expecting anyone, to create an archive like this:


using (var zip = new ZipFile())


  zip.AddFile(ReportProperties.AscxFullPath); // *EDIT: looks like i have to add a 2nd arg, "")



Mar 17, 2011 at 11:33 AM

You need a 2nd argument to AddFile().

The very first example on the homepage shows this.

Also, the documentation describes all this.

good luck.

Mar 17, 2011 at 11:58 AM
Edited Mar 17, 2011 at 12:00 PM

You are right.

But why does the call to zip.AddDirectory("") not show the same behaviour?

This is the crux of my question. After having figured out the answer, my query is not whether this is in the documentation but whether it makes sense.

When I extract the files which were added from the AddDirectory() call, they extract properly without the 2nd argument required for the AddFile() call - given above.

So, yes the first example you site has an example of a 2nd argument to the AddFile() method, but it does not also make a call to AddDirectory() where the same 2nd argument is not needed.

Is this not confusing or are you happy with this inconsistency? Or have I missed something?