public bool ZipFile(string rarName) { bool flag = false; string dirPath = AppDomain.CurrentDomain.BaseDirectory; string zipPath = dirPath + @"temp\"; ZipClass ZC = new ZipClass(); ZC.IgnoreFile = zipPath + rarName + ".rar"; int dirsCount = 0, filesCount = 0; FileSystemObject.GetTotalDF(dirPath, ref dirsCount, ref filesCount); ZipClass.zipTotal = dirsCount;//只用目录数就可以了 ZipClass.zipProgress = 0; DirectoryInfo dr = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); if (!Directory.Exists(zipPath)) { Directory.CreateDirectory(zipPath); } if (ZC.Zip(dirPath, zipPath + rarName + ".rar")) { flag = true; } return(flag); }
void Zip() { string route = dirName + "\\" + fileName; string files = route + @"\Payload%" + route + @"\iTunesArtwork%" + route + @"\iTunesMetadata.plist"; string zipRoute = dirName + "\\" + Guid.NewGuid().ToString() + ".ipa"; try { zipClass.Zip(files, zipRoute, ""); zipClass.Zip(route + ".ipa", route, ""); } catch (Exception ex) { MessageBox.Show("压缩错误"); } }
protected void DownSite_Btn_Click(object sender, EventArgs e) { DataTableHelper dtHelper = new DataTableHelper(); M_Design_SiteInfo sfMod = sfBll.SelReturnModel(SiteID); M_UserInfo mu = buser.GetLogin(); ZipClass zip = new ZipClass(); //------------------------------ //整合节点与内容,站点信息,生成XML文件 string xmlDir = function.VToP(sfMod.SiteDir + "Init/"); DataSet ds = desHelper.PackSiteToDS(sfMod.ID); if (!Directory.Exists(xmlDir)) { Directory.CreateDirectory(xmlDir); } ds.WriteXml(xmlDir + "Site.xml"); //页面信息单独存 DataTable dt = pageBll.U_Sel(mu.UserID, sfMod.ID, M_Design_Page.PageEnum.All); dt.DataSet.WriteXml(xmlDir + "Page.xml"); //模板与资源打包 string zipDir = function.VToP("/Temp/SiteDown/"); string zipPath = zipDir + sfMod.ID + ".zip"; if (!Directory.Exists(zipDir)) { Directory.CreateDirectory(zipDir); } zip.Zip(function.VToP(sfMod.SiteDir), zipPath); SafeSC.DownFile(function.PToV(zipPath), sfMod.SiteName + ".zip");//打包成为tlp? }
/// <summary> /// download more than one files /// </summary> /// <param name="context"></param> private void Downloads(HttpContext context) { //define the zip file's location [target container] 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); } } //create zip package ZipClass.Zip(Path.GetDirectoryName(zipFile) + "\\", zipFile, "", true, files.ToArray(), dirs.ToArray()); DownLoadFIle.ResponseFile(zipFile, context, false); }
/// <summary> /// compress the file(s) /// </summary> /// <param name="context"></param> private void Zip(HttpContext context) { string zipFile = context.Server.MapPath(context.Request["value1"]); string[] filepkg = context.Request["value2"].Split('|'); List <string> files = new List <string>(); List <string> dirs = new List <string>(); //put all the files and directories that needs to //be compressed into the list foreach (string item in filepkg) { string path = context.Server.MapPath(item); //distinguish between file and directory if (File.Exists(path)) { files.Add(path); } else if (Directory.Exists(path)) { dirs.Add(path); } } //source path/ destination path / password/ separate/ files array/ directory array ZipClass.Zip(Path.GetDirectoryName(zipFile) + "\\", zipFile, "", true, files.ToArray(), dirs.ToArray()); context.Response.Write("OK"); }
protected void btnCSSBackup_Click(object sender, EventArgs e) { ZipClass zip = new ZipClass(); int index = CurDirPath.LastIndexOf("/"); string fielname = CurDirPath.Substring(index + 1); string LjFile = Request.PhysicalApplicationPath.ToString() + CurDirPath; string FileToZip = LjFile.Replace("/", @"\"); string zipdirName = DateTime.Now.ToString("yyyyMMdd") + "_" + fielname; string ZipedFile = FileToZip + @"\" + zipdirName + Resources.L.风格集备份 + ".rar"; string path1 = ZipedFile; string sPath = Request.PhysicalApplicationPath.ToString() + @"temp\"; if (Directory.Exists(sPath))//判断是否存在这个目录 { } else { Directory.CreateDirectory(sPath);//不存在则创建这个目录 } string path2 = sPath + zipdirName + Resources.L.风格集备份 + ".rar"; if (zip.Zip(FileToZip, ZipedFile, "")) { function.WriteSuccessMsg(Resources.L.风格方案 + "(" + fielname + ")" + Resources.L.备份失败 + "!", "../Template/CssManage.aspx"); } else { File.Delete(path2); //如果不删除则会出现文件已存在,无法创建该文件的错误。 File.Move(path1, path2); //因为生成的ZIP文件名和文件的存放位置一样,所以要在生成以后移动到temp目录下面(temp目录是用来存放备份文件的) function.WriteSuccessMsg(Resources.L.风格方案 + "(" + fielname + ")" + Resources.L.备份成功 + "!", "../Template/CssManage.aspx"); } }
protected void BackGrup_Click(object sender, EventArgs e) { ZipClass zip = new ZipClass(); string dir = TemplateDir + Request["Dir"];//文件夹 string dir1 = TemplateDir.Substring(TemplateDir.LastIndexOf("/") + 1); int index = dir.LastIndexOf("/"); string fielname = dir.Substring(index + 1); string LjFile = Request.PhysicalApplicationPath.ToString() + dir; string FileToZip = LjFile.Replace("/", @"\"); string zipdirName = DateTime.Now.ToString("yyyyMMdd") + "_" + dir1 + "_" + fielname; string ZipedFile = FileToZip + @"\" + zipdirName + "模板集备份" + ".rar"; string path1 = ZipedFile; string sPath = Request.PhysicalApplicationPath.ToString() + @"temp\"; if (Directory.Exists(sPath))//判断是否存在这个目录 { } else { Directory.CreateDirectory(sPath);//不存在则创建这个目录 } string path2 = sPath + zipdirName + "模板集备份" + ".rar"; if (zip.Zip(FileToZip, ZipedFile, "")) { function.WriteSuccessMsg("模版方案(" + fielname + ")备份失败!", "../Template/TemplateManage.aspx"); } else { File.Delete(path2); //如果不删除则会出现文件已存在,无法创建该文件的错误。 File.Move(path1, path2); //因为生成的ZIP文件名和文件的存放位置一样,所以要在生成以后移动到temp目录下面(temp目录是用来存放备份文件的) function.WriteSuccessMsg("模版方案(" + fielname + ")备份成功!", "../Template/TemplateManage.aspx"); } }
//Compress protected void ZipSite_Click(object sender, EventArgs e) { ZipClass ZC = new ZipClass(); string ppath = iis.Sites[siteName].Applications[0].VirtualDirectories[index].PhysicalPath; string temp = Server.MapPath(SiteConfig.SiteOption.UploadDir + "Site/"); if (!Directory.Exists(temp)) { Directory.CreateDirectory(temp); } temp += siteName + ".zip"; if (ZC.Zip(ppath, temp)) { SafeSC.DownFile(function.PToV(temp), HttpUtility.UrlEncode(siteName + ".zip", System.Text.Encoding.UTF8)); } }
/// <summary> /// ../databak_fa1fb2/ /// </summary> /// <param name="path"></param> public string RunBackup() { string download = ""; this.strtmpname = this.filename.Replace("{RoundNum}", this.GetRandNum(DateTime.Now.Second).ToString()); this.backup(); //string[] strArray = this.strfilenamearr.Split(new char[] { ',' }); //for (int i = 0; i < strArray.Length; i++) //{ // download = string.Concat(new object[] { download, download, i, ":<a href="+this.bakupPath, strArray[i], " targe=_blank>", strArray[i], "</a><br/>" }); //} string str3 = string.Empty; //str3 = downPath + this.strtmpname.Replace("_{i}.txt", "") + "_bak.zip"; str3 = downPath + "SQLBackup_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_bak.zip"; ZipClass.Zip(HttpContext.Current.Server.MapPath(this.bakupPath), HttpContext.Current.Server.MapPath(str3), ""); //download = download + "<br><br><a href='" + str3 + "' target='_blank' style='font-size:16px;font-weight:bold;'>备份压缩包下载</a>"; download = "<br><br><a href='" + str3 + "' target='_blank' style='font-size:16px;font-weight:bold;'>备份压缩包下载</a>"; //删除临时文件夹 Directory.Delete(HttpContext.Current.Server.MapPath(this.bakupPath), true); return(download); }
/// <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"); }
public void download(string esting) { string FileToZip = Server.MapPath("/temp/" + esting + ".bak"); string ZipedFile = Server.MapPath("/temp/" + esting + ".rar"); //否则没有.bak文件,则先创建.bak文件。再进行压缩 string sPath = HttpContext.Current.Request.PhysicalApplicationPath + "/temp"; if (Directory.Exists(sPath)) { } else { Directory.CreateDirectory(sPath); } string sql = "backup database " + database + " to disk='" + sPath + "/" + esting + ".bak" + "' with init "; if (!SqlHelper.ExecuteSql(sql)) { if (ZC.Zip(FileToZip, ZipedFile)) { SafeSC.DownFile("/temp/" + esting + ".rar"); } } }