日期:2011-01-26  浏览次数:20408 次

//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            //根据时间自动重命名,扩展名也可以自行修改
 37            string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm";
 38            str = str.Replace("$title$", txtTitle.Text);//替换Title
 39            str = str.Replace("$content$", txtContent.Text);//替换content
 40
 41            //生成静态文件
 42            try
 43            ...{
 44                sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, code);
 45                sw.Write(str);
 46                sw.Flush();
&