Click here to Skip to main content
15,905,073 members
Please Sign up or sign in to vote.
2.20/5 (2 votes)
See more:
Hi everyone,

I want to create a zip file in .net 3.5 framework and extract the same file also.
Please help me..

Thanks
Ramana
Posted

You can use System.IO.Packaging or System.IO.Compression, these have classes that can be used to drop content into a zip file. Its not simple, however.
Here's some blog posts (these explains how to do so)
* http://weblogs.asp.net/jgalloway/archive/2007/10/25/creating-zip-archives-in-net-without-an-external-library-like-sharpziplib.aspx[^]
*http://www.4guysfromrolla.com/articles/092910-1.aspx[^]

Hope these would help.
Regards
 
Share this answer
 
v2
Comments
Ramana RK 20-Mar-14 5:37am    
Hey tnq for quick response
It is working, but I want to zip all files of a folder and extraction of file too.
milindaSnow 20-Mar-14 6:04am    
I guess You are using DotNetZip library, Its the easiest way.
ex:
using (ZipFile zip = new ZipFile())
{
// add this map file into the "images" directory in the zip archive
zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
// add the report into a different directory in the archive
zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
zip.AddFile("ReadMe.txt");
zip.Save("MyZipFile.zip");
}
Use file paths selected from a OpenFileDialog. It should work, and just add them to the archive..
(This sample code was in codeplex)
Hope you got it worked
Regards
Ramana RK 20-Mar-14 6:16am    
Hi I used below link which is you sent
http://weblogs.asp.net/jgalloway/archive/2007/10/25/creating-zip-archives-in-net-without-an-external-library-like-sharpziplib.aspx
from dis i got only file which we mention in d code but my problem is I want to zip all files of a particular folder.
milindaSnow 20-Mar-14 6:49am    
Use following where necessary..

OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
ofd.Title = "Select Files to be Archived";

DialogResult dr = ofd.ShowDialog();
try
{
using (ZipFile zip = new ZipFile())
{
foreach (string filePath in ofd.FileNames)
{
try
{
zip.AddFile(filePath);
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex.Message);
}
}
zip.Save("MyZipFile.zip");
}

MessageBox.Show("MyZipFile.zip file created");
}
catch (Exception ex)
{
MessageBox.Show("Archiving Failed");
}

Hope that helped, Let me know of any issues.
regards
 
Share this answer
 
Comments
Ramana RK 20-Mar-14 5:39am    
Hey tnq but I don't want to add other libraries like dotnetzip etc
We still use ICSharpCode.SharpZipLib, it may also be used in commercial closed source applications. Take a look at http://www.icsharpcode.net/opensource/sharpziplib/[^].
 
Share this answer
 
Comments
Ramana RK 20-Mar-14 5:53am    
Hey tnq but without adding other libraries, I want to zip.
I usually advise three options: SharpCompress, #ziplib and 7-zip for .NET. Please see my past answer: how to add file name in zip folder with same file name in c#[^].

—SA
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900