[RESOLVED] ICSharpCode.SharpZipLib.Zip + zipping files and folders
I am trying to create a zip file that will contain both folders and files from different directories. I can create a zip file with just folders, or a zip with just files. But not both of them. To do the folder you have to use the FastZip. To do the files I use ZipOutputStream. Here is what I have now.
ZipOutputStream s = new ZipOutputStream(File.Create(strfullPath));
foreach (object fileName in lbxFiles.Items)
{
strTempPath = (string)fileName;
strTempPath=strTempPath.Remove(0,strTempPath.LastIndexOf("\\") + 1);
if (!Path.HasExtension(strTempPath))
{
FastZip sz = new FastZip();
sz.CreateZip("F:\\Testing.zip", "F:\\BackUp", true, "");
ZipEntry entry1 = new ZipEntry("F:\\Testing.zip");
s.PutNextEntry(entry1);
}
else
{
FileStream fs = File.OpenRead(strTempPath);
if (password != String.Empty) s.Password = password;
strTempPath = Path.GetFileName(strTempPath);
ZipEntry entry = new ZipEntry(strTempPath);
fs.Close();
s.PutNextEntry(entry);
}
If anyone has any ideas how I can get both files and folders into the same zip file I would appreciate it.
Re: ICSharpCode.SharpZipLib.Zip + zipping files and folders
Take look at this sample code. Using J# Zip class in C# code
It should work great for your purpose.
Re: ICSharpCode.SharpZipLib.Zip + zipping files and folders
Cool thanks, that will work