Frage

I'm trying to use DotNetZip to create a zip file in C#.NET. However, I do need to include empty folders from time to time. Is this possible? Are there any tricks to make it happen?

War es hilfreich?

Lösung

There is an AddDirectory function:

zipFile.AddDirectory("\\Your\Directory\Path\");

I believe the empty directory must already exist at the location you are zipping from, so you may need to first create the empty directory on the server. Here are some examples.

Andere Tipps

McCee's solution didn't quite work for me. This however did:

First we get all the empty directories in the path of files to zip. Then we use AddDirectoryByName to append it to the zip object, i.e.

foreach (var folder in Directory.GetDirectories(pathOfFilesToZip).Where(x => !Directory.EnumerateFileSystemEntries(x).Any()))
{
    zip.AddDirectoryByName(Path.GetFileName(folder));
}       
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top