標籤: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#如何把檔案夾壓縮打包然後下載