0

I want a user to be able to upload a zip file. Then I wan't to unzip this file and display its content. How would you implement this in asp.net mvc?

Luke
  • 5,771
  • 12
  • 55
  • 77

1 Answers1

1

There are quite a few solutions for handling compressed archives in .NET and the following thread covers several options: Unzip files programmatically in .net.

DotNetZip appears to be very popular on Codeplex. I found this code sample in their documentation for listing all of the entries in a given archive in the context of a console app. It should be fairly easy to adapt to a web context:

using (ZipFile zip = ZipFile.Read(ExistingZipFile))
{
    foreach (ZipEntry e in zip)
    {
        if (header)
        {
            System.Console.WriteLine("Zipfile: {0}", zip.Name);
            if ((zip.Comment != null) && (zip.Comment != "")) 
                System.Console.WriteLine("Comment: {0}", zip.Comment);
            System.Console.WriteLine("\n{1,-22} {2,8}  {3,5}   {4,8}  {5,3} {0}",
                                 "Filename", "Modified", "Size", "Ratio", "Packed", "pw?");
            System.Console.WriteLine(new System.String('-', 72));
            header = false;
        }

        System.Console.WriteLine("{1,-22} {2,8} {3,5:F0}%   {4,8}  {5,3} {0}",
                               e.FileName,
                               e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
                               e.UncompressedSize,
                               e.CompressionRatio,
                               e.CompressedSize,
                               (e.UsesEncryption) ? "Y" : "N");
    }
}

Without actually testing it, it looks like this particular implementation may not handle folder structures, so you might need to look through their documentation a bit for more info.

Community
  • 1
  • 1
Nathan Taylor
  • 24,423
  • 19
  • 99
  • 156