I want to create zip file from my mvc.net c# application by using the .net framework classes. Please response to me as soon as possible.
Asked
Active
Viewed 3,094 times
3
-
I'd go with one of the answers below, but just in case you work in a place where they don't like third party dlls, I'll link to my answer to a similar question earlier today: http://stackoverflow.com/questions/3437770/how-to-extract-zip-file-using-dotnet-framework-4-0-without-using-third-party-dlls/3438147#3438147 – Hans Olsson Aug 09 '10 at 14:33
4 Answers
3
With .NET 4.5 you can now create zip files really easily using the .NET framework:
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
The above code taken directly from Microsoft's documentation: http://msdn.microsoft.com/en-us/library/ms404280(v=vs.110).aspx
There are other ways of generating compressed files that are further explained on the page linked to above.

bsara
- 7,940
- 3
- 29
- 47
3
One third party library I've used is http://dotnetzip.codeplex.com/
I like it a lot more than SharpZipLib -- SharpZipLib isn't really very intuitively layed out at all.

Joshua Evensen
- 1,544
- 1
- 15
- 33
1
Use external library like this one or this one. For example with DotNetZip you can make a zip file like this:
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");
}

Łukasz W.
- 9,538
- 5
- 38
- 63