一、實作步驟
在使用者操作界面,由使用者選擇需要下載下傳的檔案,系統根據所選檔案,在伺服器上建立用于存儲所選檔案的臨時檔案夾,将所選檔案拷貝至臨時檔案夾。然後調用 RAR程式,對臨時檔案夾進行壓縮,然後輸出到用戶端。最後删除臨時檔案夾。
二、代碼實作
//周遊伺服器指定檔案夾下的所有檔案
//建立臨時檔案夾
Directory.CreateDirectory(tempFolder);
{
}
RARSave(tempFolder, tempName);
\\\\" + tempName + ".rar");
代碼如下:
///
/// RAR檔案名
string the_rar;
string the_Info;
try
the_Obj = the_Reg.GetValue("");
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_StartInfo.FileName = "WinRar";//the_rar;
//打封包件存放目錄
the_Process.StartInfo = the_StartInfo;
the_Process.Close();
FileInfo fileInfo = new FileInfo(file);
Response.ClearHeaders();
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.WriteFile(fileInfo.FullName);
//删除臨時目錄下的所有檔案
Directory.Delete(tempPath);
4、DeleteFiles(string tempPath) 方法
/// 删除臨時目錄下的所有檔案
private void DeleteFiles(string tempPath)
file.Attributes = FileAttributes.Normal;