位置:海鸟网 > IT > ASP.NET >

Asp.net生成htm静态文件的两种途径

//51aspx.com生成静态页演示文件,转载请保留该信息
  2    public partial class _Default : System.Web.UI.Page
  3    ...{
  4        protected void Page_Load(object sender, EventArgs e)
  5        ...{
  6          
  7        }
  8
  9        //根据模板生成,保持在html文件夹中(部分源码搜集于网络)
 10        protected void Button1_Click(object sender, EventArgs e)
 11        ...{
 12            //源码是替换掉模板中的特征字符
 13
 14            string mbPath =Server.MapPath("template.htm");
 15            Encoding code = Encoding.GetEncoding("gb2312");
 16            StreamReader sr = null;
 17            StreamWriter sw = null;
 18            string str = null;
 19
 20            //读取
 21            try
 22            ...{
 23                sr = new StreamReader(mbPath, code);
 24                str = sr.ReadToEnd();
 25
 26            }
 27            catch (Exception ex)
 28            ...{
 29                throw ex;
 30            }
 31            finally
 32            ...{
 33                sr.Close();
 34            }
 35
 36            //根据时间自动重命名,扩展名也可以自行修改