Zipping of excel files using c#

Posted by Amritha444 under C# on 6/24/2020 | Points: 10 | Views : 1567 | Status : [Member] | Replies : 1
Sir

Im trying to zip some excel and xml files using c# using ionic.zip dll

ZipFile zip = new ZipFile();
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName("Files");
foreach (string filepath in folderPaths)
{
zip.AddFile(filepath, "Files");
}


string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
zip.Save(Path.Combine(folderPath, zipName));
foreach (string filepath in folderPaths)
{
if ((System.IO.File.Exists(Path.Combine(filepath))))
{
System.IO.File.Delete(Path.Combine(filepath));
}
}

above code works well but issue is a directory name files inside zip folder i want to remove this

when i remove zip.AddDirectoryByName("Files"); this code a folder with folderPath creatind instead of files .How to remove this .How files directly coming under zip folder




Responses

Posted by: Ishan7 on: 11/26/2020 [Member] Starter | Points: 25

Up
0
Down
Single step extraction of existing zip libraries
ZipFile.ExtractToDirectory(@”D:\dotnetcurry.zip”, @”D:\dotnetcurry\”);


Single step compression of entire folder
ZipFile.CreateFromDirectory(@”D:\devcurry”, @”D:\devcurry.zip”);



For more information follow this link
https://www.dotnetcurry.com/csharp/974/zip-archives-csharp-dotnet

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response