zoukankan      html  css  js  c++  java
  • 根据模板生成网页

    using System.Text;
    using System.IO;

                string mbPath =Server.MapPath("template.htm");
                Encoding code = Encoding.GetEncoding("gb2312");
                StreamReader sr = null;
                StreamWriter sw = null;
                string str = null;
     
                //读取
                try
                {
                    sr = new StreamReader(mbPath, code);
                    str = sr.ReadToEnd();
     
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    sr.Close();
                }
     
                //根据时间自动重命名,扩展名也可以自行修改
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm";
                str = str.Replace("$title$", txtTitle.Text);//替换Title
                str = str.Replace("$content$", txtContent.Text);//替换content
     
                //生成文件
                try
                {
                    sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, code);
     
                    sw.Write(str);
                    sw.Flush();
     
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    sw.Close();
                    Response.Write("<a href=htm/"+fileName+" target=_blank>"+fileName+"</a>已经生成!");
                }

    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    bzoj1257 [CQOI2007]余数之和sum
    bzoj1053 [HAOI2007]反素数ant
    bzoj3680 吊打XXX
    CodeVS1344 线型网络
    bzoj1925 [Sdoi2010]地精部落
    2016年北大高代考研题解答
    巴塞尔问题(Basel problem)的多种解法
    积分计算题
    PDF添加水印的办法
    Matlab技巧1:在同一坐标系上绘制两个函数图像
  • 原文地址:https://www.cnblogs.com/starcrm/p/1311014.html
Copyright © 2011-2022 走看看