[轉]C#如何把檔案夾壓縮打包然後下載

來源:互聯網
上載者:User

標籤:returns   log   pos   cli   清除   end   mat   roc   客戶   

public partial class _Default2 : System.Web.UI.Page{          protected void Page_Load(object sender, EventArgs e)          {            }          protected void Button1_Click(object sender, EventArgs e)          {              string Path = "c:\\de";              string resultPath = string.Empty;              bool rel =false;              TimeSpan nowTimeSpan=new TimeSpan();              resultPath=YaSuo(out rel, out nowTimeSpan);              ResponseFile(resultPath);          }            /// <summary>          /// 壓縮檔          /// </summary>          /// <returns>返回壓縮後的路徑</returns>          public string YaSuo(out bool bo, out TimeSpan times)          {              string rarurlPath = string.Empty;              bo = false;              //壓縮檔              string yasuoPathSave = "c:\\de\\TZ.rar";              string yasuoPath = "c:\\de\\temp";              System.Diagnostics.Process pro = new System.Diagnostics.Process();              pro.StartInfo.FileName = @"C:\Program Files\WinRAR\WinRAR.exe";//WinRAR所在路徑              //pro.StartInfo.Arguments = "a " + yasuoPathSave + " " + yasuoPath + " -r ";//dir是你的目錄名               pro.StartInfo.Arguments = string.Format("a {0} {1} -r",yasuoPathSave,yasuoPath);                 pro.Start();              times = pro.TotalProcessorTime;              bo = pro.WaitForExit(60000);//設定一分鐘              if (!bo)                  pro.Kill();              pro.Close();              pro.Dispose();              rarurlPath = yasuoPathSave;              return rarurlPath;          }              protected void ResponseFile(string filename)          {                FileInfo file = new FileInfo(filename);//建立一個檔案對象              Response.Clear();//清除所有緩衝區的內容              Response.Charset = "GB2312";//定義輸出字元集              Response.ContentEncoding = Encoding.Default;//輸出內容的編碼為預設編碼              Response.AddHeader("Content-Disposition","attachment;filename="+file.Name);              //添加頭資訊。為“檔案下載/另存新檔”指定預設檔案名稱              Response.AddHeader("Content-Length",file.Length.ToString());              //添加標頭檔,指定檔案的大小,讓瀏覽器顯示檔案下載的速度               Response.WriteFile(file.FullName);// 把檔案流發送到用戶端              Response.End();          }          }  

 

[轉]C#如何把檔案夾壓縮打包然後下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.