Tuesday 2 October 2012

How to unzip file in .Net?

Definition: How to unzip file in .Net?

Method: 


1) Add the Ionic.Zip dll through Add reference

2) Add the NameSpaces (using Ionic.Zip;)

In my previous post I show you how to make zip file. Now I will show you how to unzip that zip folder.

Code:
 protected void btnUnZip_Click(object sender, EventArgs e)
    {
        String TargetDirectory = "f:\\Zip\\myzip.zip";

        using (ZipFile zip1 = ZipFile.Read(TargetDirectory))
        {
            zip1.ExtractAll("f:\\UnZip\\myzip",
            Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite);
        }
        File.Delete(TargetDirectory);  //Delete myzip.zip file. It is optional. If you want to delete
                                                         //then delete else don't delete.
    }



No comments:

Post a Comment