Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
Can any one give me idea about how to create a zip file of a folder(contain multiple sub folders)using c#.net.
Is there any inbuilt assembly in dot net or any other?
Posted 27-Jun-12 1:10am
sharmarun1.6K
Edited 27-Jun-12 1:22am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

1. DON'T SHOUT!
2. I use ICSharpCode.SharpZipLib which can be freely downloaded and also used in commercial applications.
Code looks like that:
foreach (string folderToZip in foldersToZip)
{
    if (!string.IsNullOrWhiteSpace(folderToZip) && Directory.Exists(folderToZip))
    {
        string targetFile = Path.Combine(targetFolder, Path.GetFileName(folderToZip) + ".zip");
        ZipPath(targetFile, folderToZip, null, true, null);
    }
}
and
public static void ZipPath(string zipFilePath, string sourceDir, string pattern, bool withSubdirs, string password)
{
    FastZip fz = new FastZip();
    if (password != null)
        fz.Password = password;
 
    fz.CreateZip(zipFilePath, sourceDir, withSubdirs, pattern);
}
  Permalink  
Comments
Vani Kulkarni at 27-Jun-12 6:23am
   
Clear and concise!
Sandeep Mewara at 27-Jun-12 10:01am
   
5!
AlluvialDeposit at 25-Apr-13 2:42am
   
perfect. 5'd
Kumar Tanmay at 30-Dec-14 5:19am
   
Hi...this code is working fine....but on extracting the zip file it does not give the folder but files instead.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi
 
You can download this ICSharpCode.SharpZipLib.dll.
 
FastZip fz = new FastZip();
fz.ExtractZip(Pass Path here);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Above solution is Good but still have some doubts in it.
 
we have find a better solution to zip and unzip files and folders using asp.net with c#, vb.net.
and we also fixed the problem which creates two folder when we unzip any folder.
 
we hope this article may help you in better way. you can also download source code, dll from this link.
 
DotNetZip – Zip and Unzip in C#, VB, any .NET language
 

Regards-
Dotnet Developers to Developers Group
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 495
1 Sergey Alexandrovich Kryukov 424
2 OriginalGriff 360
3 Sascha Lefévre 255
4 Abhinav S 250
0 Sergey Alexandrovich Kryukov 10,102
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076


Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 25 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100