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 @   大da脸  阅读(299)  评论(0编辑  收藏  举报
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
历史上的今天:
2018-12-28 WinForm使用CefSharp内嵌chrome浏览器
点击右上角即可分享
微信分享提示