I have use the below snippet code to make zip folder by Ionic.zip
:
string lastFolder = packageSpec.FolderPath.Split('\\')[packageSpec.FolderPath.Split('\\').Length - 1];
string zipRoot = packageSpec.FolderPath + "\\Zip" + lastFolder;
string fileName = zipRoot + "\\" + lastFolder + ".zip";
Logging.Log(LoggingMode.Prompt, "Spliting to zip part...");
if (!Directory.Exists(zipRoot))
Directory.CreateDirectory(zipRoot);
ZipFile zip = new ZipFile();
zip.AddDirectory(packageSpec.FolderPath, zipRoot);
zip.MaxOutputSegmentSize = 200 * 1024 * 1024; // 200 MB segments
zip.Save(fileName);
it works fine to create multiple zip part but make unexpected nested folder as following desc below: if the variables are :
FolderPath = C:\MSR\Temp\Export_1
zipRoot = C:\MSR\Temp\Export_1\ZipExport_1
fileName= C:\MSR\Temp\Export_1\ZipExport_1\Export_1.zip
My source is like the image below:
1- is my source folder with it's staff to zip
2- is zip folder will contains 1 zip.AddDirectory(packageSpec.FolderPath, zipRoot);
But I am ending up with :
so these folders MSR->Temp->Export_1->ZipExport_1->ZipExport1
are extera which means Export_1.zip should have directly source folder not that nested extra folders .
does anybody knows how I can change that snippet code to do it?
thanks in advance.
I'm answering this based on the documentation link (look for AddDirectory with 2 parameters):
Which means, Your code should look like:
Result:
NOTE:
It is important to use
using
syntax, as You are not destroying the ZIP file in the end, which might cause some casualties to real run of the program (like memory leak). Please check this article on MSDN -> https://msdn.microsoft.com/en-gb/library/system.idisposable(v=vs.110).aspx?cs-lang=csharpEDIT:
As I wasn't really sure what is expected result, I was unable to provide what You want. But if You want no folder, why are You passing 2nd parameter then? Solution should be: