/// <summary> /// 解压缩 /// </summary> /// <param name="context"></param> private void UnZip(HttpContext context) { string unZipDir = context.Server.MapPath(context.Request["value1"]); string[] zipFiles = context.Request["value2"].Split('|'); foreach (string item in zipFiles) { ZipClass.UnZip(context.Server.MapPath(item), unZipDir, ""); } context.Response.Write("OK"); }
/// <summary> /// 下载多个文件 /// </summary> /// <param name="context"></param> private void DownLoads(HttpContext context) { string zipFile = context.Server.MapPath("#download.zip"); string[] fd = context.Request["value1"].Split('|'); List <string> files = new List <string>(); List <string> dirs = new List <string>(); foreach (string item in fd) { string p = context.Server.MapPath(item); if (File.Exists(p)) { files.Add(p); } else if (Directory.Exists(p)) { dirs.Add(p); } } ZipClass.Zip(Path.GetDirectoryName(zipFile) + "\\", zipFile, "", true, files.ToArray(), dirs.ToArray()); DownloadFile.ResponseFile(zipFile, context, true); }
/// <summary> /// 压缩文件 /// </summary> /// <param name="context"></param> private void Zip(HttpContext context) { string zipFile = context.Server.MapPath(context.Request["value1"]); string[] fd = context.Request["value2"].Split('|'); List <string> files = new List <string>(); List <string> dirs = new List <string>(); //将要压缩的文件或者文件夹全部存储到集合中 foreach (string item in fd) { string p = context.Server.MapPath(item); if (File.Exists(p)) { files.Add(p); } else if (Directory.Exists(p)) { dirs.Add(p); } } ZipClass.Zip(Path.GetDirectoryName(zipFile) + "\\", zipFile, "", true, files.ToArray(), dirs.ToArray()); context.Response.Write("OK"); }