在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一、创建一个控制台应用程序 二、创建一个HTML文件夹用来存放HTML
三、代码实现 static void Main(string[] args) { //当前应用程序集的执行的上级目录 string dir = Path.GetFullPath("../../"); string path = dir + "HTML"; string script = ""; string content = "<h1>我是一个h1</h1>"; string head = "<head>" + "<meta charset='UTF-8'>" + "<meta name='viewport' content='width=device-width, initial-scale=1.0'>" + "<title>测试页面</title>" + script + "</head>"; string body = "<body>" + content + "</body>"; string html = "<!DOCTYPE html>" + "<html lang='en'>" + head + body + "</html>"; Logmsg(html, "", path); } /// <summary> /// 创建HTML /// </summary> /// <param name="html">内容</param> /// <param name="title">标题</param> /// <param name="path">路径</param> public static void Logmsg(string html, string title, string path) { #region 创建HTMLif (Directory.Exists(path) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(path); } FileStream fs1 = new FileStream(path + "/" + title + DateTime.Now.ToString("yyyyMMddhhmmss") + ".html", FileMode.Create, FileAccess.Write);//创建写入文件 StreamWriter sw = new StreamWriter(fs1); sw.WriteLine(html);//开始写入值 sw.Close(); fs1.Close(); #endregion } 四、效果展示
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论