Results 1 to 3 of 3

Thread: [RESOLVED] ICSharpCode.SharpZipLib.Zip + zipping files and folders

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Resolved [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.

  2. #2
    Addicted Member
    Join Date
    Jan 2000
    Location
    BC, Canada
    Posts
    142

    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Re: ICSharpCode.SharpZipLib.Zip + zipping files and folders

    Cool thanks, that will work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width