zoukankan      html  css  js  c++  java
  • 生成html文件

    第一步:建立一个MbPage.html页面

    第二步:后台生成

      public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
                string mbPath = context.Server.MapPath("MbPage.html");
                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$", "111");//替换Title
                str = str.Replace("$content$","2222");//替换content

                //生成静态文件
                try
                {
                    sw = new StreamWriter(context.Server.MapPath("htm/") + fileName, false, code);
                    sw.Write(str);
                    sw.Flush();

                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    sw.Close();
                   context.Response.Write("恭喜<a href=htm/" + fileName + " target=_blank>" + fileName + "</a>已经生成,保存在htm文件夹下!");
                }
                context.Response.End();
            }

  • 相关阅读:
    单元测试之PowerMock
    ClickHouse单机安装
    Oracle19C ADG主备切换问题处理
    oracle dbms_metadata.get_ddl的使用方法总结
    SCN太大引发ORA-600[2252]
    异步IO ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
    Oracle Linux 7.8 多路径(Multipath)+Udev绑定磁盘
    Oracle定期清理10日分区数据
    linux如何使用umount命令强制卸载文件系统
    临时表空间使用率和被谁占用情况
  • 原文地址:https://www.cnblogs.com/115FXC/p/4424953.html
Copyright © 2011-2022 走看看