ional//EN" "http://www.w3.
<%@ Page Language="C
#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtContent" runat="server" H
eight="179px" TextMode="MultiLine" Width="350px"></asp:TextBox><
br />
<br />
<asp:Button ID="
BTnMake" runat="server" OnClick="btnMake_Click" Text="生成静态页" />
</div>
</form>
</body>
</html>
PRotected void btnMake_Click(object sender, Event
args e)
{
//替换掉模板中的特征字符
string mbPath = Server.MapPath("template.htm");
Encoding code = Encoding.GetEncoding("UTF-8");
Stre
amReader sr = null;
StreamWriter sw = null;
string str = null;
//读取
try
{
sr = new StreamReader(mbPath, code);
str = sr.ReadToEnd();
}
catch (Exception ex)
{
t
hrow ex;
}
finally
{
sr.Close();
}
//根据时间自动重命名,扩展名也可以自行修改
string fileName = DateTime.Now.ToString("
yyyyMMddHHmm") + ".htm";
str = str.Replace("$content$", txtContent.Text);//替换content
//生成静态文件
try
{
sw = new StreamWriter(Server.MapPath("~/") + fileName, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw.Close();
Response.Write("<a href=" + fileName + " mce_href=" + fileName + " target=_blank>" + fileName + "</a>已经生成!");
}
}
,暂时记录下来等毕业设计时再考虑增加动态生成静态页面,静态页面分页的功能。