JS云标签

关键代码:

//将内容写入js文件的方法
public static string WriteToJs(string content)
        {
            try
            {
                content = string.Format("{0},", content.Replace(",", ""));
                //content = Regex.Replace(content, @"[/n/r]", "");
                content = content.Trim().Replace(" ","");
                string path = HttpContext.Current.Server.MapPath("/upload/sys_yun.js");
                FileInfo info = new FileInfo(path);
                StreamWriter sr = new StreamWriter(path, true, Encoding.GetEncoding("utf-8"));//true:追加,false:覆盖
                if (!File.Exists(path))//如果不存在就创建
                {
                    sr = File.CreateText(path);
                }
                //if (info.Length != 0)//如果为空就写
                //{
                //    sr = new StreamWriter(path, false, Encoding.GetEncoding("utf-8"));
                //}
                sr.WriteLineAsync(content.Trim());
                sr.Close();
                sr.Dispose();
                return "ok";
            }
            catch (Exception ex)
            {
                return ex.Message ;
            }
            //追加内容和向txt中追加是一样的
        }

 

posted @ 2019-12-28 08:46  大da脸  阅读(298)  评论(0编辑  收藏  举报