如何使用C#.net和Asp.net与第三方ionic.zip.dll压缩和解压缩文件 [英] How to zip and unzip file using C#.net and Asp.net with third party ionic.zip.dll

查看:90
本文介绍了如何使用C#.net和Asp.net与第三方ionic.zip.dll压缩和解压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我是Sidhanta.我有一个名为ionic.zip.dll的dll文件.我被指示编写使用ionic.zip.dll和C#.net和Asp.net进行压缩和解压缩的代码.

请引导我.

致以问候
Sidhanta Tripathy

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

推荐答案

上查看可用的文档以及库本身. Codeplex [ ^ ].


检查链接:

http://social.msdn.microsoft.com/Forums/zh/sqlintegrationservices/thread/8cdefd29-4f5c-4ec7-9acf-bf58e6622b85 [ http://social.msdn.microsoft.com/Forums/eu/netfxbcl/thread/cff4fdcb-930c-4052-a4a7-15c1d69f5ac8 [
check links:

http://social.msdn.microsoft.com/Forums/en/sqlintegrationservices/thread/8cdefd29-4f5c-4ec7-9acf-bf58e6622b85[^]


http://social.msdn.microsoft.com/Forums/eu/netfxbcl/thread/cff4fdcb-930c-4052-a4a7-15c1d69f5ac8[^]


朋友,
我编写的代码还生成了受密码保护的zip文件.

Hi Friends ,
I have written code that also generate password protected zip file.

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





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


这篇关于如何使用C#.net和Asp.net与第三方ionic.zip.dll压缩和解压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆