• 生成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();
            }

  • 相关阅读:
    Android屏幕适配
    设计模式学习心得
    C语言中的作用域、链接属性与存储属性
    二级指针删除单向链表
    C++编程风格
    python中index、slice与slice assignment用法
    lua_pcall与lua_call之间的区别
    lua-C++ userdata使用
    lua中调用C++函数
    C++中为什么有时要使用extern "C"
  • 原文地址:https://www.cnblogs.com/115FXC/p/4424953.html
Copyright © 2020-2023  润新知