I am trying to create a zip file from code, I'm using dotnetzip
I want to create a directory tree in the folder that doesn't exist on disk. How do I do this?
I have tried using AddDirectory
but this seems to want to find the directory on disk. I have also tried AddEntry but this requires some content.
My files are stored in a SQL Server using the FileStream option and organised in a hierarchy there.
I wrote this recursive method to do it but the AddDirectory line doesn't work.
private void GetFiles(ZipFile zipFile, Folder folder, string path)
{
zipFile.AddDirectory(folder.FolderName, path);
foreach (var file in folder.Files)
zipFile.AddEntry(file.FileName, file.FileData);
foreach(var subfolder in folder.SubFolders)
{
GetFiles(zipFile, subfolder, path + "\\" + subfolder.FolderName);
}
}
You can use AddDirectoryByName to create a new directory in the zipfile instead of importing a directory