DotNetZip add files without creating folders
31,480
How about just:
zip.AddFile(file,"");
or
zip.AddFile(file,@"\");
Author by
fearofawhackplanet
Updated on November 15, 2020Comments
-
fearofawhackplanet over 3 years
using (ZipFile zip = new ZipFile()) { foreach(string file in Directory.GetFiles(folder)) { zip.AddFile(file, Path.GetFileName(file)); } zip.Save("test.zip")); }
Each time I add a file, it's creating a new subfolder for it.
So I want to end up with:
test.zip - myDoc.doc - myPdf.pdf
but I'm ending up with:
test.zip - myDoc.doc - myDoc.doc - myPdf.pdf - myPdf.pdf
-
fearofawhackplanet over 13 yearsThats makes it even worse. A filepath of for example
Documents\Process\Practices\text.doc
will create a subfolder in the .zip for each level in the path so you end up withtest.zip -> Documents -> Process -> Practices -> text.doc
. -
Praveen almost 11 years@Fosco This works. Is there any complete documentation for this? I am using IonicZip.dll from nuGet.
-
Mou about 9 yearsdotnet zip compression ratio not good. i zip a 152 KB doc file with dotnet zip and when zip was created then i was zip file size was 136KB. is there any tweak exist which create small size zip file. share the knowledge. thanks
-
Clay over 8 years@Mou - doc files are now like .zip files, and they are already mostly compressed. There are still sections inside that aren't compressed - so that external programs can read out property/summary information, etc. - but generally, they're already pretty compact.
-
Avtandil Kavrelishvili about 6 years@Fosco thank you for great solution. You save my time.