Reputation: 39
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.
Upvotes: 3
Views: 3150
Reputation: 1566
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.
Upvotes: 3
Reputation: 8249
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.
Upvotes: 3
Reputation: 9745
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");
}
Upvotes: 1