zoukankan      html  css  js  c++  java
  • ASP.NET动态生成HTML页面

     1/*首先建一个html模板,在相应的位置加上标致,如:$Title$,$Content$之类的。
     2
     3在这里,HTML里的标致为:$htmlFromat[0],$htmlFromat[1]
     4
     5template.htm   //为模板文件*/

     6
     7void htmlWrite()
     8  {
     9   string[] format = new string[3];  //定义和html页面数目一直的数组
    10   StringBuilder sb = new StringBuilder();
    11
    12   try
    13   {
    14    using(StreamReader sr = new StreamReader(Server.MapPath("template.htm")))
    15    {
    16     string line;
    17     while((line = sr.ReadLine())!=null)
    18     {
    19      sb.Append(line);
    20     }

    21     sr.Close();
    22    }

    23   }

    24   catch
    25   {}
    26   format[0]="内容XXXXXX";
    27   format[1]="内容YYYYYYY";
    28   format[2]="内容ZZZZZZ";
    29   
    30   for(int i=0;i<3;i++)
    31   {
    32    sb.Replace("$htmlFromat["+i+"]",format[i]);
    33   }

    34
    35   try
    36   {
    37    string file = DateTime.Now.ToString("yyyyMMddHHssmm")+".html";
    38    File.Create(Server.MapPath(file));
    39    using(StreamWriter sw = new StreamWriter(Server.MapPath(file),false,Encoding.GetEncoding("GB2312")))
    40    {
    41     sw.WriteLine(sb);
    42     sw.Flush();
    43     sw.Close();
    44     Response.Write("OK");
    45    }

    46    
    47   }

    48   catch(Exception er)
    49   {
    50    er.Message.ToString();
    51   }

    52  }

    53
    54
  • 相关阅读:
    sql 临时表循环更新月租金
    董事长审核租金异常处理备份
    datetable导出成Excel
    DateTable导出添加时间段
    button 美化
    JS计算两日期之间相差的月份
    刚做的JS,备份一下(空代表格计算)
    Windows 框架基础开发流程
    照片切换
    Sql datetime类型数据默认1900
  • 原文地址:https://www.cnblogs.com/Lewis/p/449568.html
Copyright © 2011-2022 走看看