public string getStatePage(string title, string content) { //思路是替换掉模板中的特征字符 string mbPath = Server.MapPath("pro.htm"); Encoding code = Encoding.GetEncoding("UTF-8"); 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(); } getChild("0"); menu = "<ul id=/"menu-main-menu/" class=/"nav sf-menu sf-vertical/">" + sb + "</ul>"; //根据时间自动重命名,扩展名也可以自行修改 string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm"; str = str.Replace("$title$", title);//替换Title str = str.Replace("$content$", content);//替换content str = str.Replace("$adr$", Function.getInfo(Server.MapPath("adr.txt")));//替换adr str = str.Replace("$word$", Function.getInfo(Server.MapPath("words.txt")));//替换word str = str.Replace("$menu$", menu);//替换menu //生成静态文件 try { sw = new StreamWriter(Server.MapPath("../htm/") + fileName, false, code); sw.Write(str); sw.Flush(); } catch (Exception ex) { fileName = "wrong.html"; } finally { sw.Close(); } return fileName; }