Click here to Skip to main content
15,173,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

I have done Zipping using Windowsbase dll. Now I want to do Unzipping using the same dll. I will upload the zip file and it should unzip into the server.

Thanks in advance,
Posted
Comments
StianSandberg 16-Jul-12 7:53am
   
http://codingsense.wordpress.com/2010/12/05/zipunzip-using-system-io-package-in-net/
AmitGajjar 16-Jul-12 8:06am
   
have you tried ? what error/problem you have ?
Sandeep Mewara 16-Jul-12 8:13am
   
And the question/issue is?

1 solution

I use this code in one of my applications

C#
public void UnZip(string pathToZipFile, string destinationPath)
{
    try
    {
        using (Package package = ZipPackage.Open(pathToZipFile, FileMode.Open, FileAccess.Read))
        {
            foreach (PackagePart part in package.GetParts())
            {
                var target = Path.GetFullPath(Path.Combine(destinationPath, part.Uri.OriginalString.TrimStart('/')));
                var targetDir = target.Remove(target.LastIndexOf('\\'));

                if (!Directory.Exists(targetDir))
                    Directory.CreateDirectory(targetDir);

                using (Stream source = part.GetStream(FileMode.Open, FileAccess.Read))
                {
                    source.CopyTo(File.OpenWrite(target));
                }
            }
        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message + " (Event: UnZip)");
    }
}


If you want to see my complete code, you can find it on my blog > http://perschluter.com/creating-zip-files-in-c-sharp/[^]
   
v2
Comments
maajanes 20-Jul-12 5:09am
   
source.CopyTo(File.OpenWrite(target));

this line shows, 'System.IO.Stream' does not contain a definition for 'CopyTo' and no extension method 'CopyTo' accepting a first argument of type 'System.IO.Stream' could be found (are you missing a using directive or an assembly reference?) error.
Phrone 20-Jul-12 9:40am
   
You need to add System.IO namespace:
using System.IO;

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