Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi Friends ,
I am Sidhanta. I have a dll file named ionic.zip.dll. I am being instructed to write coding for zipping and unzipping using C#.net and Asp.net with ionic.zip.dll.

Kindly guide me.

With Regards
Sidhanta Tripathy
Posted

Have a look at the documentation available along with the library itself on Codeplex[^].
 
Share this answer
 
Hi Friends ,
I have written code that also generate password protected zip file.

C#
// Extract files from Zip file
        protected void btnExtract_Click(object sender, EventArgs e)
        {
            if (fuBrowse.HasFile)
            {
                string uploadedFile = Path.GetFileName(fuBrowse.PostedFile.FileName);
                string location = Server.MapPath("~/ZipFiles/" + uploadedFile);
                fuBrowse.SaveAs(location);
                ZipFile fileToExtract = ZipFile.Read(location);
                fileToExtract.Password = "";
                fileToExtract.ExtractAll(Server.MapPath("~/extracted_file"), ExtractExistingFileAction.DoNotOverwrite);
                gridviewExtractedFiles.DataSource = fileToExtract.Entries;
                gridviewExtractedFiles.DataBind();
                lblMessage.Text = "Archive extracted successfully and containes following files";
            }
            else
            {
                lblMessage.Text = "No File Choosen";
            }
        }


C#
//Making a file to password protected zip where password is chosen from a text box.

protected void btnZip_Click(object sender, EventArgs e)
       {
           if (fuBrowse.HasFile)
           {
               Response.ContentType = "application/zip";
               Response.AddHeader("content-disposition",
                "attachment;filename=a.zip");
               Response.Cache.SetCacheability(HttpCacheability.NoCache);
               string fileName = Path.GetFileName(fuBrowse.PostedFile.FileName);
               string fileLocation = Server.MapPath("~/zip_uploadedfile/" + fileName);
               fuBrowse.SaveAs(fileLocation);
               ZipFile createZipFile = new ZipFile();
               if (txtPassword.Text == string.Empty)
               {
                   lblMessage.Text = "Please put the password";
               }
               createZipFile.Password = txtPassword.Text.ToString();
               createZipFile.Encryption = EncryptionAlgorithm.PkzipWeak;
               createZipFile.AddFile(fileLocation, string.Empty);
               createZipFile.Save(Server.MapPath("~/zip_zipfile/a.zip"));
               gridviewExtractedFiles.DataSource = createZipFile.Entries;
               gridviewExtractedFiles.DataBind();
               lblMessage.Text = "Zip sucessfully created";
               Response.TransmitFile("~/zip_zipfile/a.zip");
               Response.End();

           }
           else
           {
               lblMessage.Text = "No File Choseen";
           }
       }
 
Share this answer
 
v3
You should use google before asking questions. A quick search came up with the following getting started that will help you:
http://dotnetzip.codeplex.com/wikipage?title=Getting-Started&referringTitle=Home[^]
 
Share this answer
 

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