3

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.

1
  • 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: stackoverflow.com/questions/3437770/… Commented Aug 9, 2010 at 14:33

4 Answers 4

3

Have you looked into SharpZipLib?

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

Comments

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");
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.