/// <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); }
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 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? }
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); }
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"); } }
/// <summary> /// 查询是否有更新 /// </summary> /// <param name="msg"></param> /// <returns>0 不需要更新 1 需要更新 -1 异常</returns> public static int CheckUpdate(out string msg) { MDownloadfile[] updateFileList = null; string json = TransClass.CheckUpdate(PubGlobal.Envionment.APPVersion, ref updateFileList); MMessage <string> mmsg = Converter.Deserialize <MMessage <string> >(json); if (mmsg.Flag && updateFileList != null && updateFileList.Length > 0) { string path = PubGlobal.Envionment.UpdateFolderPath; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (MDownloadfile file in updateFileList) { try { ZipClass.UnzipBytesToFile(file.FileContent, path + @"\" + file.FileName); } catch (Exception ex) { msg = ex.Message; return(-1); } } msg = string.Empty; return(1); } else { msg = "不需要更新"; return(0); } }
/// <summary> /// 升级前备份旧系统文件 /// </summary> /// <param name="rootPath">系统根目录</param> /// <param name="backupPath">备份目录</param> public static string BackupOldFiles(string rootPath, string backupPath) { //检查文件夹是否存在 string tempPath = Path.Combine(rootPath, "_temp\\backupBeforeUpdate"); if (Directory.Exists(tempPath)) { DirectoryInfo d = new DirectoryInfo(tempPath); We7Helper.DeleteFileTree(d); } //不需要复制的文件夹 string[] folderList = new string[] { "_data", "_skins", "_temp", "_backup", "Plugins", "log" }; ArrayList folders = ArrayList.Adapter(folderList); DirectoryInfo di = new DirectoryInfo(rootPath); DirectoryInfo[] ds = di.GetDirectories(); //复制当前网站目录结构,到tempPath foreach (DirectoryInfo d in ds) { if (!folders.Contains(d.Name.ToLower())) { We7Helper.CopyDirectory(d.FullName, Path.Combine(tempPath, d.Name)); } } FileInfo[] files = di.GetFiles(); foreach (FileInfo f in files) { File.Copy(f.FullName, Path.Combine(tempPath, f.Name)); } if (!Directory.Exists(backupPath)) { Directory.CreateDirectory(backupPath); } string[] FileProperties = new string[2]; FileProperties[0] = tempPath; //临时目录,将被压缩 FileProperties[1] = Path.Combine(backupPath, "backup-" + DateTime.Today.ToString("yyyy-MM-dd-") + DateTime.Now.GetHashCode() + ".zip"); //压缩后的目录 //压缩文件 try { ZipClass.ZipFileMain(FileProperties); //压缩之后删除临时文件 DirectoryInfo d = new DirectoryInfo(tempPath); We7Helper.DeleteFileTree(d); return(FileProperties[1]); } catch { } return(""); }
protected void CreateZip(string FileName) { //string CopyToPath = Server.MapPath(Constants.TempBasePath);//目标文件夹 string CopyToPath = String.Format("{0}\\Templates.{1}\\controls", Server.MapPath("~/_temp/"), Path.GetFileNameWithoutExtension(FileName)); //在目标文件夹 创建文件夹.Files及子文件夹 string stylesPath = String.Format("{0}\\styles", CopyToPath); //css文件目录 string groupsPath = String.Format("{0}\\groups", CopyToPath); //模板组文件目录 string imagePath = String.Format("{0}\\images", CopyToPath); //模板组文件目录 Directory.CreateDirectory(stylesPath); Directory.CreateDirectory(groupsPath); //模板组Jpg预览图片文件 string JpgFile = Server.MapPath(String.Format("/{0}/{1}.jpg", Constants.TemplateGroupBasePath, FileName)); //模板组Xml文件 string XmlFile = Server.MapPath(String.Format("/{0}/{1}", Constants.TemplateGroupBasePath, FileName)); //拷贝模板组文件 if (File.Exists(JpgFile)) { File.Copy(JpgFile, String.Format("{0}/{1}.jpg", groupsPath, FileName), true); } if (File.Exists(XmlFile)) { File.Copy(XmlFile, String.Format("{0}/{1}", groupsPath, FileName), true); } string imgPath = String.Format("{0}/images", Server.MapPath(Constants.TemplateBasePath)); CopyFolder(imagePath, imgPath, true); string templateFile = Server.MapPath(Constants.TemplateBasePath); CopyFolder(CopyToPath, templateFile, false); string cssPath = String.Format("{0}/styles", Server.MapPath(Constants.TemplateBasePath)); CopyFolder(stylesPath, cssPath, true); //创建res文件夹 string resPath = String.Format("{0}\\Templates.{1}\\res", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName)); Directory.CreateDirectory(resPath); //创建版本文件 //CreateVersion(resPath); string[] FileProperties = new string[2]; FileProperties[0] = String.Format("{0}\\Templates.{1}", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName));; //压缩目录 //FileProperties[1] = String.Format("{0}/{1}.zip", Server.MapPath(Constants.TemplateGroupBasePath), FileName);//压缩后的目录 FileProperties[1] = String.Format("{0}/Templates.{1}.zip", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName)); //压缩后的目录 //压缩文件 try { ZipClass.ZipFileMain(FileProperties); DonwloadHyperLink.NavigateUrl = String.Format("~/{0}/Templates.{1}.zip", Constants.TempBasePath.TrimStart('\\').Trim('/'), Path.GetFileNameWithoutExtension(FileName)); DeleteFolder(String.Format("{0}\\Templates.{1}", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName))); } catch { } }
/// <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 Page_Load(object sender, EventArgs e) { if (!B_Admin.IsSuperManage(badmin.GetAdminLogin().AdminId)) { function.WriteErrMsg("只有超级管理员才能访问该页!!"); } if (function.isAjax()) { //返回进度 Response.Write(ZipClass.GetPercent(ZipClass.zipTotal, ZipClass.zipProgress)); Response.Flush(); Response.End(); } database = StrHelper.GetAttrByStr(SqlHelper.ConnectionString, "initial catalog"); if (!IsPostBack) { if (!B_ARoleAuth.Check(ZLEnum.Auth.other, "DevCenter")) { function.WriteErrMsg("你没有对该模块的访问权限"); } if (!badmin.CheckSPwd(Session["Spwd"] as string)) { SPwd.Visible = true; } else { maindiv.Visible = true; } this.DatabasePath.Value = DateTime.Now.ToString("MMdd") + "ZoomlaCMS"; this.SiteText.Value = DateTime.Now.ToString("yyyyMMdd_HHmmss") + "全站备份"; MyBind(); Call.SetBreadCrumb(Master, "<li><a href='" + CustomerPageAction.customPath2 + "I/Main.aspx'>工作台</a></li><li><a href='DatalistProfile.aspx'>扩展功能</a></li> <li><a href='RunSql.aspx'>开发中心</a></li><li><a href='BackupRestore.aspx'>备份与还原数据</a></li>" + Call.GetHelp(69)); } }
public byte[] ExportWebModifications(IEnumerable <string> rowIds) { var webmodRecords = rowIds.Select(rowId => this._assharedentryRepository.WebModificationRead(new Webmodcriteria { webmodRowID = rowId })).Where(returnRecord => returnRecord != null).ToList(); return(webmodRecords.Count > 0 ? ZipClass.Compress(JsonConvert.SerializeObject(webmodRecords)) : null); }
public void UnzipFileWork(int userID, HttpContext ct, string sPath, string tPath) { FileInfo f = new FileInfo(sPath);//获取文件大小,用于判断进度 ZipClass zip = new ZipClass(); ct.Application[userID + "uzT"] = f.Length;//需要解压的文件总字节数 zip.UnZipFiles(sPath, tPath, userID + "uzP", ct); }
public byte[] ExportExtensions(IEnumerable <string> rowIds) { var webextendRecords = rowIds.Select(rowId => this._assharedinquiryRepository.WebExtensionRetrieve(new Webextendcriteria { webextensionrowid = rowId })).Where(returnRecord => returnRecord != null).ToList(); return(webextendRecords.Count > 0 ? ZipClass.Compress(JsonConvert.SerializeObject(webextendRecords)) : null); }
public static void MyUnZipWork(object state) { StationGroup sg = (StationGroup)state; ZipClass zip = new ZipClass(); //zip.UnZipFiles(rootPath + @"\SourceCode\ZoomlaCMS.zip", rootPath + @"\"); StationGroup.SetupPath = StationGroup.SetupPath.Replace("/", "\\");//将格式符替换为物理路径格式符\ zip.UnZipFiles(StationGroup.RootPath + StationGroup.ZipSavePath + StationGroup.ZipName, StationGroup.RootPath + StationGroup.SetupPath); }
/// <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"); }
void CreateTempFile() { string DirectoryName = String.Format("Templates.{0}", Path.GetFileNameWithoutExtension(FileName)); //目标文件夹 string CopyToPath = String.Format("{0}/Templates.{1}", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName)); //源文件夹 string CopyFromPath = TemplateHelper.TemplateGroupPath; CopyFromPath = String.Format("{0}/{1}", CopyFromPath, Path.GetFileNameWithoutExtension(FileName)); CopyToPath = String.Format("{0}/{2}/Skin/{1}", CopyToPath, Path.GetFileNameWithoutExtension(FileName), DirectoryName); //复制模板文件夹 CopyFolder(CopyToPath, CopyFromPath, true); //预览图片源 string JpgFile = String.Format("{0}.xml.jpg", CopyFromPath); //Xml文件源 string XmlFile = String.Format("{0}.xml", CopyFromPath); CopyToPath = String.Format("{0}/Templates.{1}", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName));//目标文件夹 //复制XML文件、预览图片 if (File.Exists(JpgFile)) { string str = String.Format("{0}/{2}/Skin/{1}.xml.jpg", CopyToPath, Path.GetFileNameWithoutExtension(FileName), DirectoryName); File.Copy(JpgFile, str, true); } if (File.Exists(XmlFile)) { File.Copy(XmlFile, String.Format("{0}/{2}/Skin/{1}", CopyToPath, FileName, DirectoryName), true); } //创建res文件夹 //string resPath = String.Format("{0}/res", CopyToPath); //Directory.CreateDirectory(resPath); //创建版本文件 //CreateVersion(resPath); //TODO:css、ascx文件路径处理 //打包 string[] FileProperties = new string[2]; FileProperties[0] = CopyToPath; //压缩目录 FileProperties[1] = String.Format("{0}/Templates.{1}.zip", Server.MapPath(Constants.TempBasePath), Path.GetFileNameWithoutExtension(FileName)); //压缩后的目录 //压缩文件 try { ZipClass.CreateTemplateZip(FileProperties); DonwloadHyperLink.NavigateUrl = String.Format("~/{0}/Templates.{1}.zip", Constants.TempBasePath.TrimStart('/').TrimStart('\\'), Path.GetFileNameWithoutExtension(FileName)); DeleteFolder(CopyToPath); } catch { } }
static void ZipConfig() { string [] FileProperties = new string[2]; string Path = Application.streamingAssetsPath; Debug.Log("Path=" + Path); //待压缩文件目录 FileProperties[0] = System.IO.Path.Combine(Path, "Config"); //压缩后的目标文件 FileProperties[1] = System.IO.Path.Combine(Path, "Config.zip"); ZipClass Zc = new ZipClass(); Zc.ZipFileMain(FileProperties); }
public IEnumerable <Webextendrecord> ImportExtensionsPartOne(byte[] zipFile) { var importObjectString = ZipClass.Decompress(zipFile); var webextendrecords = JsonConvert.DeserializeObject <IEnumerable <Webextendrecord> >(importObjectString); var importExtensions = webextendrecords as Webextendrecord[] ?? webextendrecords.ToArray(); foreach (var webextendrecord in importExtensions) { if (webextendrecord.cono != 0) { webextendrecord.cono = this._tokenObject.Cono; } } return(importExtensions); }
public frmWeCleared() { InitializeComponent(); // Classe d'enregistrement des parametres Settings = new SettingsClass(this); Settings.ReadMainSettings(); // Attribution du WoWPath WoWPath = MainSettings["WoWPath"]; if (IsWoWPathValid(WoWPath)) { lblPath.Text = WoWPath; } // Addons Parser class AddonsParser = new AddonsParser(this); // Zip Class ZipClass = new ZipClass(this); // Démarrer le timer général. tmrRefresh.Start(); tmrRefresh_Tick(this, EventArgs.Empty); // Notify Icon NIcon = new NotifyIcon { BalloonTipIcon = ToolTipIcon.Info, BalloonTipText = "Vous pouvez réouvrir We Cleared Client via le system tray.", BalloonTipTitle = "We Cleared minimisé.", Icon = Properties.Resources.Icon, Text = "Cliquez pour réouvrir We Cleared.", Visible = false }; NIcon.MouseClick += NIcon_Click; // Mises à jour de l'UI dataGridAddons.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True; dataGridAddons.RowTemplate.Height = 50; btnUpdate.BackColor = Settings.GetEnabled("AutoUpdate") ? Color.DarkGreen : Color.DarkRed; DefineTooltips(); // ISharpUpdatable UI lblUpdateClient.Text = ApplicationAssembly.GetName().Version.ToString(); Updater = new SharpUpdater(this); Updater.DoUpdate(); }
//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)); } }
void OnGUI() { if (GUI.Button(new Rect(400, 130, 100, 50), "ZipClass")) { string [] FileProperties = new string[2]; //待压缩文件目录 FileProperties[0] = @"/Users/jiangcheng/Desktop/ziptest"; //压缩后的目标文件 FileProperties[1] = @"/Users/jiangcheng/Desktop/a.zip"; ZipClass Zc = new ZipClass(); Zc.ZipFileMain(FileProperties); //Debug.Log(DeviceInfo.StreamingPath); // ZipClass Zc=new ZipClass(); // Zc.ZipFile(@"/Users/jiangcheng/Desktop/ziptest",@"/Users/jiangcheng/Desktop/a.zip",6,2048); } if (GUI.Button(new Rect(400, 200, 100, 50), "UnZipClass")) { string ConfigPath = System.IO.Path.Combine(DeviceInfo.StreamingPath, "Config.zip"); //string ConfigMD5 = MessageDigest_Algorithm.getFileMd5Hash(ConfigPath); Debug.Log(Core.Data.guideManger.getBasePath()); string [] FileProperties = new string[2]; //待解压的文件 FileProperties[0] = ConfigPath; //解压后放置的目标目录 FileProperties[1] = Core.Data.guideManger.getBasePath(); UnZipClass UnZc = new UnZipClass(); UnZc.UnZip(FileProperties); } if (GUI.Button(new Rect(400, 270, 100, 50), "GetMD5")) { string ConfigPath = System.IO.Path.Combine(DeviceInfo.StreamingPath, "Config.zip"); string ConfigMD5 = MessageDigest_Algorithm.getFileMd5Hash(ConfigPath); Debug.Log(ConfigMD5); } if (GUI.Button(new Rect(400, 340, 100, 50), "DownLoad")) { string ConfigPath = System.IO.Path.Combine(DeviceInfo.StreamingPath, "Config.zip"); string ConfigMD5 = MessageDigest_Algorithm.getFileMd5Hash(ConfigPath); test_DownloadResource(ConfigMD5); } }
protected void Page_Load(object sender, EventArgs e) { //http://update.z01.com/Template/Bear/view.jpg if (function.isAjax()) { string action = Request.Form["action"]; string value = Request.Form["value"]; int userID = buser.GetLogin().UserID; Response.Clear(); switch (action) { case "getTempP": Response.Write(ZipClass.GetPercent(Convert.ToInt64(Application[userID + "downTempT"]), Convert.ToInt64(Application[userID + "downTempP"]))); break; case "setdefault": string tempdir = @"/Template/" + value; SiteConfig.SiteOption.TemplateDir = tempdir; SiteConfig.SiteOption.CssDir = tempdir + "/style"; SiteConfig.Update(); Response.Write(""); break; } Response.End(); } //EC.GetRemoteObj remote = new EC.GetRemoteObj(); //remote.Urlutf8("" + serverdomain + "/api/gettemplate.aspx?menu=getprojectinfodir&proname=" + Server.UrlEncode(proname)); if (!IsPostBack) { Panel1.Visible = true; LblTitle.Text = ProName + "[作者:" + GetAuthor() + "]"; tempname.Text = ProName; string prodir = "/template/" + ProDir + "/"; tempimg.Text = "<a class=\"lightbox\" href=\"" + serverdomain + prodir + "view.jpg\"><img src=\"" + serverdomain + prodir + "View.jpg\"></a>"; DownFile dw = DownFileWork; string TempUrl = serverdomain + "/template/" + ProDir + ".zip"; string TempZipFile = SiteConfig.SiteMapath() + "\\template\\" + ProDir + ".zip"; TempUrl = TempUrl.Replace(@"\\", @"\"); TempZipFile = TempZipFile.Replace("/", @"\").Replace(@"\\", @"\"); //function.WriteErrMsg(TempZipFile + "||||" + TempUrl); Application[buser.GetLogin().UserID + "downTempT"] = GetFileSize(TempUrl); dw.BeginInvoke(buser.GetLogin().UserID, HttpContext.Current, TempUrl, TempZipFile, null, null, null); Call.SetBreadCrumb(Master, "<li><a href='" + customPath2 + "Main.aspx'>工作台</a></li><li><a href='TemplateSetOfficial.aspx'>方案设置</a></li><li class=\"active\">下载方案</li>"); } }
private void pictureBox3_Click(object sender, EventArgs e) { System.Windows.Forms.SaveFileDialog openFileDialog1 = new System.Windows.Forms.SaveFileDialog(); openFileDialog1.Filter = "zip文件(*.zip)|*.zip"; string savePath = ""; if (openFileDialog1.ShowDialog() == DialogResult.OK) { savePath = openFileDialog1.FileName; } else if (openFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } ZipClass zip = new ZipClass(); zip.ZipFileFromDirectory(Globals.ThisAddIn.exerciseJsonPath + "Temp3\\" + paperNameReal, savePath, 0); this.label3.Visible = true; timer.Start(); }
public void ReadData(string filePath) { DirectoryInfo root = new DirectoryInfo(filePath); foreach (FileInfo f in root.GetFiles()) { if (Path.GetExtension(f.FullName) == ".json") { Jsdata = ReadJson(f.FullName); } else if (Path.GetExtension(f.FullName) == ".task") { Taskinfo = ReadTask(f.FullName); } else if (Path.GetExtension(f.FullName) != ".json" && Path.GetExtension(f.FullName) != ".task") { ZipClass zf = new ZipClass(); zf.filename = f.Name; zf.filepath = f.FullName; ZipFile = zf; } } }
/// <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); }
public static void BaleZIP() { string balePath = EditorTools.mExportFolderLocationFloder; if (!Directory.Exists(balePath)) { Directory.CreateDirectory(balePath); } string savePath = EditorTools.mExportFolderLocationFloder + EditorTools.mGame + ".ZIP"; if (File.Exists(savePath)) { File.Delete(savePath); } string [] FileProperties = new string[2]; //待压缩文件目录 FileProperties[0] = balePath; //压缩后的目标文件 FileProperties[1] = savePath; ZipClass Zc = new ZipClass(); Zc.ZipFileMain(FileProperties); }
/// <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 string CheckUpdate(string oldVersion, ref List <MDownloadfile> fileList) { MMessage <string> msg = new MMessage <string>(); bool update = false; string newVersion; try { string _path = @"\Updates"; string ss = Server.MapPath(_path); if (File.Exists(Server.MapPath(_path + @"\POS.exe"))) { newVersion = FileVersionInfo.GetVersionInfo(Server.MapPath(_path + @"\POS.exe")).FileVersion; //判断版本号 string[] oldVers = oldVersion.Split('.'); string[] newVers = newVersion.Split('.'); for (int i = 0; i < 4; i++) { //逐位比较版本号 if (int.Parse(oldVers[i]) == int.Parse(newVers[i])) { //旧版本号等于新版本号 update = false; continue; } if (int.Parse(oldVers[i]) > int.Parse(newVers[i])) { //旧版本号大于新版本号 throw new Exception("本地版本比服务器版本高"); } if (int.Parse(oldVers[i]) < int.Parse(newVers[i])) { //旧版本号小于新版本号 update = true; break; } } if (update) { #region 生成配置文件 //写配置文件 using (StreamWriter wt = new StreamWriter(Server.MapPath(_path + @"\Version.inf"), false)) { wt.WriteLine(newVersion); wt.Close(); } #endregion DirectoryInfo updateFolder = new DirectoryInfo(Server.MapPath(_path)); fileList = new List <MDownloadfile>(); foreach (FileInfo file in updateFolder.GetFiles()) { fileList.Add(new MDownloadfile(file.Name, ZipClass.ZipFileToBytes(file.FullName))); } msg.Flag = true; //msg.Content = fileList; return(Converter.Serialize(msg)); } else { msg.Flag = false; msg.Text = "已是最新程序"; return(Converter.Serialize(msg)); } } else { msg.Flag = false; msg.Text = "更新文件不存在"; return(Converter.Serialize(msg)); } } catch (Exception ex) { WriteLog("Update", false, ex.Message); msg.Flag = false; msg.Text = ex.Message; msg.Content = null; return(Converter.Serialize(msg)); } }
/// <summary> /// ds2012 /// 循环遍历DataTable数据,导出Excel /// </summary> /// <param name="dt"></param> /// <param name="title"></param> /// <param name="colsName"></param> public static void OutToExcel(System.Data.DataTable dt, string title, string[] colsName) { System.Web.UI.Page page = new System.Web.UI.Page(); System.Data.DataTable ddt = new System.Data.DataTable(); for (int i = 0; i < colsName.Length; i++) { DataColumn dc = new DataColumn(colsName[i].Split('=')[1]); ddt.Columns.Add(dc); } for (int k = 0; k < dt.Rows.Count; k++) { DataRow dr = ddt.NewRow(); for (int i = 0; i < colsName.Length; i++) { dr[colsName[i].Split('=')[1]] = dt.Rows[k][colsName[i].Split('=')[0]]; } ddt.Rows.Add(dr); } System.Web.UI.WebControls.DataGrid dataGrid = new System.Web.UI.WebControls.DataGrid(); dataGrid.DataSource = ddt.DefaultView; dataGrid.AllowPaging = false; dataGrid.HeaderStyle.BackColor = System.Drawing.Color.Gray; dataGrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Center; dataGrid.HeaderStyle.Font.Bold = true; dataGrid.ItemStyle.HorizontalAlign = HorizontalAlign.Left; dataGrid.DataBind(); System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); dataGrid.RenderControl(hw); if (!Directory.Exists(page.Server.MapPath("../UserExcel/"))) { Directory.CreateDirectory(page.Server.MapPath("../UserExcel/")); } string fullpath = page.Server.MapPath("../UserExcel/FileName.xls"); System.IO.StreamWriter sw = System.IO.File.CreateText(fullpath); sw.Write(tw.ToString()); sw.Close(); string where = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); //压缩后的目标文件 string zipPath = page.Server.MapPath("../UserExcel/") + where + ".rar"; ZipClass Zc = new ZipClass(); string err = ""; Zc.ZipFile(fullpath, zipPath, out err); //删除压缩前的文件 System.IO.File.Delete(fullpath); System.IO.FileInfo file = new System.IO.FileInfo(zipPath); System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.ClearContent(); System.Web.HttpContext.Current.Response.ClearHeaders(); System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name).Replace('+', ' ')); System.Web.HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString()); System.Web.HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "binary"); System.Web.HttpContext.Current.Response.ContentType = "application/zip"; System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); System.Web.HttpContext.Current.Response.WriteFile(file.FullName); System.Web.HttpContext.Current.Response.Flush(); System.Web.HttpContext.Current.Response.End(); }
protected void Page_Load(object sender, EventArgs e) { IdentityAnalogue ia = new IdentityAnalogue(); ia.CheckEnableSA(); //---------------指定管理员权限管理 M_Site_SiteList siteM = new M_Site_SiteList(); B_Site_SiteList siteBll = new B_Site_SiteList(); if (badmin.CheckLogin()) { //如果是管理员登录则不判断 } else if (buser.CheckLogin()) { string siteID = iis.Sites[siteName].Id.ToString(); //非管理员用户登录,开始判断 siteM = siteBll.SelByUserID(buser.GetLogin().UserID.ToString());//查找有无为该用户分配权限 if (siteM == null || !siteBll.AuthCheck(siteID, buser.GetLogin().UserID.ToString())) { function.WriteErrMsg("你没有管理站点的权限"); } this.Title = "独立控制台-文件浏览"; } else { function.WriteErrMsg("无权访问该页面"); return; } //-------------- if (function.isAjax())//删除 { string[] siteInfo; //站点名,索引,目标文件 string action = Request.Form["action"]; if (action.Equals("beginDown"))//开始下载 { siteInfo = Request.Form["fullPath"].Split(':'); Int32.TryParse(siteInfo[1], out index); StationGroup.RootPath = iis.Sites[siteInfo[0]].Applications[0].VirtualDirectories[index].PhysicalPath; if (!Directory.Exists(StationGroup.RootPath + StationGroup.ZipSavePath)) { Directory.CreateDirectory(StationGroup.RootPath + StationGroup.ZipSavePath); } if (File.Exists(StationGroup.RootPath + StationGroup.ZipSavePath + StationGroup.ZipName)) { File.Delete(StationGroup.RootPath + StationGroup.ZipSavePath + StationGroup.ZipName); } //ThreadPool.QueueUserWorkItem(MyThreadWork, tempPath + StationGroup.ZipName); ThreadPool.QueueUserWorkItem(MyThreadWork, sg); Response.End(); } else if (action.Equals("getProgress")) { Response.Write(progStatus); Response.End(); } else if (action.Equals("getUnZipProg")) { //根据长度 ,计算出百分比值后返回 Response.Write(ZipClass.GetPercent(ZipClass.unZipTotal, ZipClass.unZipProgress)); Response.End(); } siteInfo = Request.Form["fullPath"].Split(':'); int i = 0; if (siteInfo.Length < 3 || !Int32.TryParse(siteInfo[1], out i)) { Response.Write("信息错误,无法删除"); Response.Flush(); Response.End(); } string path = GetPath(siteInfo[0], i, siteInfo[2]);//获取全路径 if (action.Equals("del")) { try { if (!DeleteDirAndFile(path)) { Response.Write("文件不存在"); Response.Flush(); Response.End(); } } catch (Exception ex) { Response.Write(ex.Message); Response.Flush(); Response.End(); }//Response.Write("删除失败,目标文件正在使用或你无权限删除"); } else if (action.Equals("rename")) { string newPath = GetPath(siteInfo[0], i, "\\" + siteInfo[3]); //Response.Write(siteInfo[2]+":"+siteInfo[3]); if (!path.Equals(newPath)) { RenameDirAndFile(path.Trim(), newPath.Trim()); } } Response.Clear(); Response.Write(1); Response.Flush(); Response.End(); } //----------------AJAX END; siteName = Server.HtmlEncode(Request.QueryString["siteName"]); if (string.IsNullOrEmpty(siteName) || string.IsNullOrEmpty(Request.QueryString["index"]) || iis.Sites[siteName] == null) { function.WriteErrMsg("未选择要访问的站点名或该站点不存在."); } Int32.TryParse(Request.QueryString["index"], out index); StationGroup.RootPath = iis.Sites[siteName].Applications[0].VirtualDirectories[index].PhysicalPath; if (string.IsNullOrEmpty(iis.Sites[siteName].Bindings[index].Host)) { url = "http://LocalHost:" + iis.Sites[siteName].Bindings[index].EndPoint.Port; } else { url = "http://" + iis.Sites[siteName].Bindings[index].Host + ":" + iis.Sites[siteName].Bindings[index].EndPoint.Port; } if (!IsPostBack) { Call.HideBread(Master); Repeater1.DataSource = GetDirAndFileList(); Repeater1.DataBind(); string command = Request["command"];//如beginSetup开始安装等,快云安装传过来的 if (!string.IsNullOrEmpty(command)) { switch (command) { case "beginSetup": Page.ClientScript.RegisterStartupScript(this.GetType(), "", "beginDown();", true); //调用前台开始下载方法 break; default: break; } }//Command End; } }