private void RemoveTemplates(string dirName) { string fullPath = Utils.GetMapPath("../../plugins/" + dirName + "/"); //插件目录物理路径 DirectoryInfo tempPath = new DirectoryInfo(fullPath + @"templet\"); //插件模板目录实例 XmlNodeList xnList = XML.ReadNodes(fullPath + DTKeys.FILE_PLUGIN_XML_CONFING, "plugin/urls"); if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite" && xe.Attributes["page"] != null) { if (xe.Attributes["name"] != null && xe.Attributes["type"] != null) { //遍历插件模板目录下的站点目录 if (tempPath.Exists) { foreach (DirectoryInfo dirInfo in tempPath.GetDirectories()) { //删除对应站点下的aspx文件 FileHelp.DeleteFile(sysConfig.webpath + DTKeys.DIRECTORY_REWRITE_ASPX + "/" + dirInfo.Name + "/" + xe.Attributes["page"].Value); } } } } } } }
/// <summary> /// 查找不存在的图片并删除已移除的图片及数据 /// </summary> public void DeleteList(SqlConnection conn, SqlTransaction trans, List <Model.article_albums> models, int channel_id, int article_id) { StringBuilder idList = new StringBuilder(); if (models != null) { foreach (Model.article_albums modelt in models) { if (modelt.id > 0) { idList.Append(modelt.id + ","); } } } string delIds = idList.ToString().TrimEnd(','); StringBuilder strSql = new StringBuilder(); strSql.Append("select id,thumb_path,original_path from " + databaseprefix + "article_albums where channel_id=" + channel_id + " and article_id=" + article_id); if (!string.IsNullOrEmpty(delIds)) { strSql.Append(" and id not in(" + delIds + ")"); } DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString()); foreach (DataRow dr in ds.Tables[0].Rows) { int rows = DbHelperSQL.ExecuteSql(conn, trans, "delete from " + databaseprefix + "article_albums where id=" + dr["id"].ToString()); //删除数据库 if (rows > 0) { FileHelp.DeleteFile(dr["thumb_path"].ToString()); //删除缩略图 FileHelp.DeleteFile(dr["original_path"].ToString()); //删除原图 } } }
//删除更新的旧文件 public void DeleteFile(int id, string filePath) { Model.article_attach model = GetModel(id); if (model != null && model.file_path != filePath) { FileHelp.DeleteFile(model.file_path); } }
/// <summary> /// 删除附件文件 /// </summary> public void DeleteFile(List <Model.article_attach> models) { if (models != null) { foreach (Model.article_attach modelt in models) { FileHelp.DeleteFile(modelt.file_path); } } }
/// <summary> /// 删除相册图片 /// </summary> public void DeleteFile(List <Model.article_albums> models) { if (models != null) { foreach (Model.article_albums modelt in models) { FileHelp.DeleteFile(modelt.thumb_path); FileHelp.DeleteFile(modelt.original_path); } } }
//卸载插件 protected void lbtnUnInstall_Click(object sender, EventArgs e) { ChkAdminLevel("sys_plugin_config", DTEnums.ActionEnum.UnLoad.ToString()); //检查权限 //插件目录 string pluginPath = Utils.GetMapPath("../../plugins/"); BLL.plugin bll = new BLL.plugin(); //查找列表 for (int i = 0; i < rptList.Items.Count; i++) { string currDirName = ((HiddenField)rptList.Items[i].FindControl("hidDirName")).Value; CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { //是否已安装 Model.plugin model = bll.GetInfo(pluginPath + currDirName + @"\"); if (model.isload == 1) { string currPath = pluginPath + currDirName + @"/bin/"; if (Directory.Exists(currPath)) { string[] file = Directory.GetFiles(currPath); foreach (string f in file) { FileInfo info = new FileInfo(f); //复制DLL文件 if (info.Extension.ToLower() == ".dll") { //删除站点目录下DLL文件 string newFile = Utils.GetMapPath(sysConfig.webpath + @"bin/" + info.Name); if (File.Exists(newFile)) { FileHelp.DeleteFile(newFile); } } } } //执行SQL语句 bll.ExeSqlStr(pluginPath + currDirName + @"\", @"plugin/uninstall"); //删除URL映射 bll.RemoveNodes(pluginPath + currDirName + @"\", @"plugin/urls"); //删除后台导航记录 bll.RemoveMenuNodes(pluginPath + currDirName + @"\", @"plugin/menu"); //删除站点目录下的aspx文件 RemoveTemplates(currDirName); //修改plugins节点 bll.UpdateNodeValue(pluginPath + currDirName + @"\", @"plugin/isload", "0"); } } } AddAdminLog(DTEnums.ActionEnum.UnLoad.ToString(), "卸载插件"); //记录日志 JscriptMsg("插件卸载成功!", "plugin_list.aspx", "parent.loadMenuTree"); }
//删除文件 protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("sys_site_templet", DTEnums.ActionEnum.Delete.ToString()); //检查权限 for (int i = 0; i < rptList.Items.Count; i++) { string fileName = ((HiddenField)rptList.Items[i].FindControl("hideName")).Value; CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { FileHelp.DeleteFile("../../templates/" + this.skinName + "/" + fileName); } } AddAdminLog(DTEnums.ActionEnum.Delete.ToString(), "删除模板文件,模板:" + this.skinName);//记录日志 JscriptMsg("文件删除成功!", Utils.CombUrlTxt("templet_file_list.aspx", "skin={0}", this.skinName)); }
/// <summary> /// 插入 /// </summary> /// <param name="models">数据映射模型集合结果</param> /// <param name="isOverride">是否覆盖写入数据</param> /// <returns>是否成功</returns> public override bool Insert(M[] models, bool isOverride) { if (CheckData.IsSizeEmpty(models)) { models = new M[] { }; } if (isOverride) { FileHelp.DeleteFile(this.AbsFilePath); } XmlSerializer xs = new XmlSerializer(typeof(M[])); using (FileStream fs = File.Open(this.AbsFilePath, FileMode.OpenOrCreate, FileAccess.Write, this.FileShare)) { using (XmlWriter sw = XmlWriter.Create(fs, Config_XmlWriterSettings())) { xs.Serialize(sw, models); sw.Flush(); } } return(true); }
public ActionResult DeleteSystemLog(int LogType, string FileName) { var result = new StandardJsonResult(); result.Try(() => { if (!ModelState.IsValid) { throw new KnownException(ModelState.GetFirstError()); } LogPhysicalPath = Server.MapPath(logDir); LogPhysicalPath = PreHandlerLogDir(LogPhysicalPath, LogType); string FilePath = LogPhysicalPath + FileName; FileHelp flp = new FileHelp(); flp.DeleteFile(FilePath); }); return(result); }
/// <summary> /// 插入 /// </summary> /// <param name="models">数据映射模型集合结果</param> /// <param name="isOverride">是否覆盖写入数据</param> /// <returns>是否成功</returns> public override bool Insert(M[] models, bool isOverride) { if (CheckData.IsSizeEmpty(models)) { models = new M[] { }; } if (isOverride) { FileHelp.DeleteFile(this.AbsFilePath); } using (FileStream fs = File.Open(AbsFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare)) { using (StreamWriter sw = new StreamWriter(fs, YTS.Tools.Const.Format.FILE_ENCODING)) { foreach (M model in models) { string line = ModelToString(model); sw.WriteLine(line); } sw.Flush(); } } return(true); }
protected void DelFile(string FileName) { FileHelp.DeleteFile(FileName); }