//遍历服务器指定文件夹下的
所有文件
string path = "uploads/Image/";
string serverPath = Server.MapPath(path);
//创建临时文件夹
string tempN
ame = DateTime.Now.ToString("
yyyyMMddHHMMss");
string tempFolder = Path
.COMbine(serverPath, tempName);
Directory.CreateDirectory(tempFolder);
DirectoryInfo folder = new DirectoryInfo(serverPath);
for
each (Fil
einfo file in folder.GetFiles())
{
string filename = file.Name;
File.Copy(serverPath + "/" + filename, tempFolder + "/" + filename);
}
//ZKHel
PEr.JSHelper.Alert("图片拷贝成功!");
//产生@R_65_
1261@,及文件输出
RARSave(tempFolder, tempName);
DownloadRAR(tempFolder + "
\\\\" + tempName + ".rar");
/// <summary>
/// 生成RAR文件
/// </summary>
/// <param name="path">
存放复制文件的目录</param>
/// <param name="rarPatch">RAR文件存放目录</param>
/// <param name="rarName">RAR文件名</param>
PRivate void RARSave(string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
Object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenS
ubKey(@"WinRAR");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + rarName + " -r";
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = "WinRar";//the_rar;
the_StartInfo.
arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.W
aitForEx
IT();
the_Process.Close();
}
catch (Exception)
{
t
hrow;
}
}
/// <summary>
/// 下载生成的RAR文件
/// </summary>
private void DownloadRAR(string file)
{
FileInfo fileInfo = new FileInfo(file);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-
transfer-Encoding", "binary");
Response.ContentType = "application/
octet-stream";
Response.ContentEncoding =
System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
string tempPath = file.Substring(0, file.LastIndexOf("
\\\\"));
//删除临时目录下的所有文件
DeleteFiles(tempPath);
//删除
空目录
Directory.Delete(tempPath);
Response.End();
}