public async Task <JsonResult> UpdateTempContent(string Id, string context) { PageResponse reponse = new PageResponse(); try { reponse.status = -1; reponse.code = "200"; if (string.IsNullOrEmpty(Id)) { reponse.msg = "未选择模板"; return(Json(reponse)); } var model = _sqliteFreeSql.Select <TemplateConfig>().Where(m => m.Id.Equals(Id)).ToOne(); _sqliteFreeSql.Dispose(); if (model == null) { reponse.msg = "模板不存在"; return(Json(reponse)); } FileHelp fileHelp = new FileHelp(); await fileHelp.WriteViewAsync(model.TempatePath, context); reponse.msg = "修改成功!"; reponse.status = 0; return(Json(reponse)); } catch (Exception ex) { reponse.msg = ex.Message; reponse.status = -1; reponse.code = "500"; return(Json(reponse)); } }
private int GetLogTypeforFullName(string FullName) { int logtype = 0; FileInfo fle = new FileHelp().Getfile(FullName); string dirName = ""; if (fle != null) { dirName = fle.Directory.Name; dirName = dirName.ToLower(); if (dirName == errorPath.ToLower()) { logtype = 1; } else if (dirName == debugPath.ToLower()) { logtype = 2; } else if (dirName == infoPath.ToLower()) { logtype = 3; } } return(logtype); }
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); } } } } } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Model.manager admin_info = GetAdminInfo(); //管理员信息 //登录信息 if (admin_info != null) { BLL.manager_log bll = new BLL.manager_log(); Model.manager_log model1 = bll.GetModel(admin_info.user_name, 1, DTEnums.ActionEnum.Login.ToString()); if (model1 != null) { //本次登录 litIP.Text = model1.user_ip; } Model.manager_log model2 = bll.GetModel(admin_info.user_name, 2, DTEnums.ActionEnum.Login.ToString()); if (model2 != null) { //上一次登录 litBackIP.Text = model2.user_ip; litBackTime.Text = model2.add_time.ToString(); } } LitUpgrade.Text = FileHelp.GetDomainStr(DTKeys.CACHE_OFFICIAL_UPGRADE, DESEncrypt.Decrypt(DTKeys.FILE_URL_UPGRADE_CODE, "DT")); LitNotice.Text = FileHelp.GetDomainStr(DTKeys.CACHE_OFFICIAL_NOTICE, DESEncrypt.Decrypt(DTKeys.FILE_URL_NOTICE_CODE, "DT")); //Utils.GetDomainStr("dt_cache_domain_info", "http://www.YTS.net/upgrade.ashx?u=" + Request.Url.DnsSafeHost + "&i=" + Request.ServerVariables["LOCAL_ADDR"]); } }
/// <summary> /// 统一保存文件 /// </summary> private void FileSave(HttpContext context, HttpPostedFile upFiles, bool isWater) { if (upFiles == null) { showError(context, "请选择要上传文件!"); return; } //检查是否允许匿名上传 /*if (sysConfig.fileanonymous == 0 && !new ManagePage().IsAdminLogin() && !new BasePage().IsUserLogin()) * { * showError(context, "禁止匿名非法上传!"); * return; * }*/ //获取文件信息 string fileName = upFiles.FileName; byte[] byteData = FileHelp.ConvertStreamToByteBuffer(upFiles.InputStream); //获取文件流 //开始上传 string remsg = new UpLoad().FileSaveAs(byteData, fileName, false, isWater); Dictionary <string, object> dic = JSON.Deserialize <Dictionary <string, object> >(remsg); string status = dic["status"].ToString(); string msg = dic["msg"].ToString(); if (status == "0") { showError(context, msg); return; } string filePath = dic["path"].ToString(); //取得上传后的路径 showSuccess(context, fileName, filePath); //输出成功提示 }
/// <summary> /// 保存远程文件到本地 /// </summary> /// <param name="sourceUri">URI地址</param> /// <returns>上传后的路径</returns> public string RemoteSaveAs(string sourceUri) { if (!IsExternalIPAddress(sourceUri)) { return("{\"status\": 0, \"msg\": \"INVALID_URL\"}"); } var request = HttpWebRequest.Create(sourceUri) as HttpWebRequest; using (var response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { return("{\"status\": 0, \"msg\": \"Url returns " + response.StatusCode + ", " + response.StatusDescription + "\"}"); } if (response.ContentType.IndexOf("image") == -1) { return("{\"status\": 0, \"msg\": \"Url is not an image\"}"); } try { byte[] byteData = FileHelp.ConvertStreamToByteBuffer(response.GetResponseStream()); return(FileSaveAs(byteData, sourceUri, false, false)); } catch (Exception e) { return("{\"status\": 0, \"msg\": \"抓取错误:" + e.Message + "\"}"); } } }
/// <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 async Task <string> ReadWord() { var setting = await FileHelp.GetWordArrByTxt("Setting", "WordsFileSetting-word.txt"); foreach (var wordFile in setting) { var wordArr = FileHelp.GetWordsByWordDocument("EnWords", wordFile); foreach (var wordLine in wordArr) { var arr = wordLine.Split(':', ':'); if (arr.Length < 2) { throw new NullReferenceException("文本行数据异常"); } // 英文单词 string word = arr[0].Trim(); // 注释 string annotation = arr[1].Trim(); } } return(null); }
/// <summary> /// 删除上传文件 /// </summary> /// <param name="fileUri">相对地址或网址</param> public void DeleteFile(string fileUri) { //文件不应是上传文件,防止跨目录删除 if (fileUri.IndexOf("..") == -1 && fileUri.ToLower().StartsWith(sysConfig.webpath.ToLower() + sysConfig.filepath.ToLower())) { FileHelp.DeleteUpFile(fileUri); } }
private string GetSysLogStr(string FullName) { FileHelp flp = new FileHelp(); string str = flp.FileToStr(FullName); str = str.Replace("\r\n", "<br/>"); return(str); }
//删除更新的旧文件 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); } }
void Generate() { MapSettings ms = new MapSettings(eDepthDimess, textureSavePathRelativeToProject, mapDataSavePathRelativeToProject); FileHelp.SaveStringFile(JsonConvert.SerializeObject(ms), FileHelp.GetFullPathByDataPathRelativePath(MapSettings.mapSettingsProfilesPath)); AssetDatabase.Refresh(); }
/// <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); } } }
static void Initialize() { string path = string.Format(@"{0}/{1}", Application.dataPath, MapSettings.mapSettingsProfilesPath); if (FileHelp.FileExist(path)) { ms = FileHelp.LoadJsonFormatObject <MapSettings>(path); EditorWindow.GetWindow <MapSetter>().InitWithExistProfiler(); } errorStyle.normal.textColor = Color.red; }
/// <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); } } }
public string ExistFilePath() { Article a = new Article() { ID = ArticleID }; string folderPath = a.AttachmentUrlPath + "/thumbnail/"; FileHelp.IsDirExists(folderPath); return(Server.MapPath(folderPath)); }
//卸载插件 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"); }
static void InitMapSettings(MapGenerator window) { if (FileHelp.FileExistInDataPathRelativePath(mapSettingsProfilesPath)) { ms = FileHelp.LoadJsonFormatObjectByDataPathRelativePath <MapSettings> (mapSettingsProfilesPath); } else { EditorWindow.GetWindow <MapGenerator>().Close(); throw new System.Exception(@"easy map cannot find map settings, did you forgot to generate one,please check 'MapTool/MapSettings'."); } }
/* ======================== Override End ======================== */ #endregion #region ====== Method for decorating pages 页面装饰方法 ====== /// <summary> /// 输出HTML代码: 返回图片内容 /// </summary> protected string imgResult(string sourceImgUrl) { StringBuilder resultStr = new StringBuilder(); if (!FileHelp.FileExists(sourceImgUrl)) { return(String.Format("文件不存在<br/>{0}", sourceImgUrl)); } resultStr.Append(String.Format("<a href=\"{0}\" target=\"_blank\">", sourceImgUrl)); resultStr.Append(String.Format("<img class=\"img-box\" src=\"{0}\" />", sourceImgUrl)); resultStr.Append("</a>"); return(resultStr.ToString()); }
static void Main(string[] args) { string[] files = FileHelp.GetFilesByDirectory(@"D:\youdaoyun", "*.md"); Random random = new Random(DateTime.Now.Second); int r = random.Next(files.Length - 1); string md = File.ReadAllText(files[r]); string html = MarkDownHelp.MarkdownToHtml(md); File.WriteAllText(@"D:\1.html", html); //Process.Start(@"d:\1.html"); System.Console.WriteLine(html); System.Console.WriteLine("Hello World!"); }
//删除文件 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="sqlconnect"></param> /// <returns></returns> public async Task <JsonResult> AddTemp(TemplateConfig temp) { PageResponse reponse = new PageResponse(); try { //判断模板是否存在 var path = AppContext.BaseDirectory + temp.TempatePath; if (System.IO.File.Exists(path)) { reponse.code = "500"; reponse.status = -1; reponse.msg = "模板已存在,创建失败!"; return(Json(reponse)); } else { FileHelp fileHelp = new FileHelp(); await fileHelp.WriteViewAsync(temp.TempatePath, ""); } var insert = _sqliteFreeSql.Insert <TemplateConfig>(); temp.Id = Guid.NewGuid().ToString(); var res = insert.AppendData(temp); var i = insert.ExecuteAffrows(); _sqliteFreeSql.Dispose(); if (i > 0) { reponse.code = "200"; reponse.status = 0; reponse.msg = "添加成功!"; reponse.data = temp; } else { reponse.code = "500"; reponse.status = -1; reponse.msg = "添加失败!"; } return(Json(reponse)); } catch (Exception ex) { reponse.code = "500"; reponse.status = -1; reponse.msg = "添加失败!"; return(Json(reponse)); } }
void Initialize() { if (!valid) { return; } ms = FileHelp.LoadJsonFormatObjectByDataPathRelativePath <MapSettings> (MapSettings.mapSettingsProfilesPath); mapData = FileHelp.LoadJsonFormatObjectByDataPathRelativePath <MapData> (string.Format("{0}/{1}.json", ms.mapDataSavePathRelativeToProject, mapName)); widthDelta = mapTexTrans.rect.width / mapData.GetMapWidth(); heightDelta = mapTexTrans.rect.height / mapData.GetMapWidth(); staticMark = new List <GameObject>(); movingObjRelateMarkDic = new Dictionary <GameObject, GameObject>(); }
public string GetPage(Params par) { string html = FileHelp.OnlyRead(par.PathTemplet.FullName); string aspx = html; Func <string, Params, string>[] funcs = AnalysisFunctions(); for (int i = 0; i < funcs.Length; i++) { Func <string, Params, string> item = funcs[i]; if (CheckData.IsObjectNull(item)) { continue; } aspx = item(aspx, par); } return(aspx); }
private void UpLoadFile(HttpContext context) { Model.sysconfig sysConfig = YTS.SystemService.GlobalSystemService.GetInstance().Config.Get <Model.sysconfig>(); //检查是否允许匿名上传 /*if (sysConfig.fileanonymous == 0 && !new ManagePage().IsAdminLogin() && !new BasePage().IsUserLogin()) * { * context.Response.Write("{\"status\": 0, \"msg\": \"禁止匿名非法上传!\"}"); * return; * }*/ string _delfile = DTRequest.GetString("DelFilePath"); //要删除的文件 string fileName = DTRequest.GetString("name"); //文件名 byte[] byteData = FileHelp.ConvertStreamToByteBuffer(context.Request.InputStream); //获取文件流 bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (DTRequest.GetQueryString("IsWater") == "1") { _iswater = true; } if (DTRequest.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (byteData.Length == 0) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } UpLoad upLoad = new UpLoad(); string msg = upLoad.FileSaveAs(byteData, fileName, _isthumbnail, _iswater); //删除已存在的旧文件 if (!string.IsNullOrEmpty(_delfile)) { upLoad.DeleteFile(_delfile); } //返回成功信息 context.Response.Write(msg); context.Response.End(); }
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); }
bool ValidateSavePath() { bool result = false; if (!FileHelp.FolderExistInDataPathRelativePath(textureSavePathRelativeToProject)) { throw new System.Exception("the save path for map textures does not exists!\n" + FileHelp.GetFullPathByDataPathRelativePath(textureSavePathRelativeToProject)); } else if (!FileHelp.FolderExistInDataPathRelativePath(mapDataSavePathRelativeToProject)) { throw new System.Exception("the save path for map data does not exists!\n" + FileHelp.GetFullPathByDataPathRelativePath(mapDataSavePathRelativeToProject)); } else { result = true; } 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); } 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); }
private void preHandlerDown(string FullName) { if (string.IsNullOrEmpty(FullName)) { return; } FileHelp flp = new FileHelp(); MemoryStream ms = flp.FileToStream(FullName); Response.ContentType = "application/octet-stream"; long length = 0; if (ms != null && ms.Length > 0) { length = ms.Length; Response.BinaryWrite(ms.ToArray()); } else { Response.ContentType = "text/html"; Response.Write("<script>alert('日志不存在,或者无内容!');window.opener = null;window.close();</script>"); Response.End(); return; } string fileNmae = ""; // flp.GetFileNameforFullName(FullName); FileInfo fileinfo = flp.Getfile(FullName); if (fileinfo != null) { fileNmae = fileinfo.Name; if (fileinfo.Extension.ToLower() != ".log") { fileNmae += ".log"; } } Response.AddHeader("Content-Disposition", "attachment; filename=" + fileNmae + ";Content-Length=" + length); Response.Flush(); Response.End(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.sites model) { string old_build_path = dal.GetBuildPath(model.id); if (string.IsNullOrEmpty(old_build_path)) { return(false); } if (dal.Update(model, old_build_path)) { if (old_build_path.ToLower() != model.build_path.ToLower()) { //更改频道分类对应的目录名称 FileHelp.MoveDirectory(sysConfig.webpath + DTKeys.DIRECTORY_REWRITE_ASPX + "/" + old_build_path, sysConfig.webpath + DTKeys.DIRECTORY_REWRITE_ASPX + "/" + model.build_path); FileHelp.MoveDirectory(sysConfig.webpath + DTKeys.DIRECTORY_REWRITE_HTML + "/" + old_build_path, sysConfig.webpath + DTKeys.DIRECTORY_REWRITE_HTML + "/" + model.build_path); } return(true); } return(false); }