欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.Net MVC_DotNetZip簡單使用方法,解決文件壓縮的問題

 更新時(shí)間:2016年06月03日 11:51:28   投稿:jingxian  
下面小編就為大家?guī)硪黄狝SP.Net MVC_DotNetZip簡單使用方法,解決文件壓縮的問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

準(zhǔn)備工作:

 在vs工具欄中找到NuGet

 

下載DotNetZip

現(xiàn)在就可以使用DotNetZip強(qiáng)大的類庫了,在這里我給出一些簡單的使用。

public ActionResult Export()
    {
      using (ZipFile zip = new ZipFile(System.Text.Encoding.Default))
      {
        zip.AddFile(Server.MapPath("~/Img/2.png"), "Images");
        zip.AddFile(Server.MapPath("~/File/1.pdf"), "Files");
        zip.Save(Server.MapPath("~/ZIP/Test.zip"));
        return File(Server.MapPath("~/ZIP/Test.zip"),
                      "application/zip", "sample.zip");
      }
    }

其中“System.Text.Encoding.Default”是解決中文亂碼問題。

從字面上就可以理解zip.AddFile就是從指定路徑把文件加入到zip中,后面的參數(shù)“Images"和“Files”就是說解壓后看到了兩個(gè)目錄。

zip.Sava就是保存zip文件到某個(gè)目錄。

 解壓后    

要是文件都在一個(gè)目錄的話還可以這樣:

public ActionResult Export()
    {
      using (ZipFile zip = new ZipFile())
      {
        zip.AddDirectory(Server.MapPath("~/Img/"));
        zip.Save(Server.MapPath("~/ZIP/Test.zip"));
        return File(Server.MapPath("~/ZIP/Test.zip"),
                      "application/zip", "sample.zip");
      }
    }

下面是加密

public ActionResult Export()
    {
      using (ZipFile zip = new ZipFile())
      {
        zip.Password="123";
        zip.AddDirectory(Server.MapPath("~/Img/"));
        zip.Save(Server.MapPath("~/ZIP/Test.zip"));
        return File(Server.MapPath("~/ZIP/Test.zip"),
                      "application/zip", "sample.zip");
      }
    }

以上這篇ASP.Net MVC_DotNetZip簡單使用方法,解決文件壓縮的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論