asp.net 檔案壓縮zip下載

來源:互聯網
上載者:User

標籤:






 今天分享下昨天做的一個東西 asp.net 的檔案  zip 批量下載,首先你需要去 到http://dotnetzip.codeplex.com這個網站下載zip 的包,在裡面找到 Ionic.Zip.dll  引用到你的項目中去

/// <summary> /// 批量zip下載 /// </summary> /// <param name="Listimg">這裡Listimg 是一個數群組類型</param> public void CreateZip(string Listimg) { string[] imgs = Listimg.Split(‘,‘); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.BufferOutput = false; //網站檔案產生一個readme.txt的讀我檔案(可以不寫) String readmeText = String.Format("README.TXT" +Environment.NewLine+"網址址:http://www.aicoffees.com" ); HttpContext.Current.Response.ContentType = "application/zip";//以zip 形式輸出 HttpContext.Current.Response.AddHeader("content-disposition", "inline; filename=\"Photo.zip");//壓縮下載的名字 //批量壓縮操作 using (ZipFile zip = new ZipFile()) { for (int i = 0; i < imgs.Length; i++) {///在壓縮包內添加上面的讀我檔案,文字編碼是系統預設編碼形式 zip.AddEntry("Readme.txt", readmeText, Encoding.Default); zip.Password = "www.aicoffees.com";//給壓縮包設定密碼 zip.Encryption = EncryptionAlgorithm.WinZipAes256;//加密方式 zip.AddFile(HttpContext.Current.Server.MapPath(imgs[i].ToString()), "");//這裡"" 我給的是空就是壓縮時不設定檔案夾,如果需要取什麼名字只需要在“”裡面加上就可以了,這裡是一個重載方法,如果 zip.AddFile(HttpContext.Current.Server.MapPath(imgs[i].ToString()), "");這樣寫的話,zip 就會預設把你的image從根目錄一直壓縮到你的檔案所在目錄。 } zip.Save(HttpContext.Current.Response.OutputStream); } HttpContext.Current.Response.Close(); }

以上是自己的一點小總結,come on

asp.net 檔案壓縮zip下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.