asp.net 生成静态页面思路
1.建立一个空的模板页面
2.建立一个aspx页面去读取模板信息,并替换相关的资料
3.写入/htm产生新的htm
--------------------------------------------------------Template--------------------------------------------------------
---------------------------------------------------------aspx-------------------------------------------------------------
using System; using System.Collections; using System.Configuration; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using System.Text; using System.Net; using System.Data.SqlClient; public partial class test_ExcuteHtml : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string sql = string.Empty; // string strName =Session["login_name"].ToString().Trim(); string strDate = DateTime.Now.ToString("yyyy年MM月dd日HH:mm"); /* string strTitle =string.Empty; if (Request.Form["titlez"] != null) { strTitle = Request.Form["titlez"].ToString().Trim(); } string strContent =string.Empty; if (Request.Form["bodyz"] != null) { strContent = Request.Form["bodyz"].ToString().Trim(); } string strClass = string.Empty; if (Request.Form["cla"] != null) { strClass = Request.Form["cla"].ToString().Trim(); } */ string strTitle = "我是标题"; string strClass = "我是类别"; string strContent = "我是内容"; string strName = "名字"; //根据实际情况填写 // Encoding Code = Encoding.GetEncoding("Big5"); Encoding Code = Encoding.GetEncoding("GB2312"); StreamReader Sr = StreamReader.Null; StreamWriter Sw = StreamWriter.Null; String Str = String.Empty; //读取远程路径 string Sessionpath = Session["Path"].ToString().Trim(); WebRequest temp = WebRequest.Create(Sessionpath + "template.htm"); WebResponse myTemp = temp.GetResponse(); Sr = new StreamReader(myTemp.GetResponseStream(), Code); //读取 try { Sr = new StreamReader(myTemp.GetResponseStream(), Code); Str = Sr.ReadToEnd(); } catch (Exception ex) { throw ex; } finally { Sr.Close(); } string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm"; //文件名 //写入 try { Sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, Code); Str = Str.Replace("$class{1}quot;, strClass); Str = Str.Replace("$title{1}quot;, strTitle); Str = Str.Replace("$content{1}quot;, strContent); Str = Str.Replace("$name{1}quot;,strName); Str = Str.Replace("$date{1}quot;,strDate); Sw.Write(Str); Sw.Flush(); } catch (Exception ex) { throw ex; } finally { Sw.Close(); strTitle = "<a href=../../Form/G_it/News/htm/" + fileName + " target=_blank>" + strTitle + "</a>"; //sql = "INSERT INTO [News1] (classz,titlez,namez,datez) VALUES('" + strClass + "','" + strTitle + "', '" + strName + "','" + strDate + "')"; //string ch = nb.ExecSQL(sql).ToString().Trim(); // ch = ch.ToLower(); // Response.Write("{success:true,ch:" + ch + "}"); } } }