方法一:根據模板生成
思路分析:
包含起來
替換$value$
參考代碼如下:
<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<title> $title$ 生成靜態頁的Demo|
<style type="text/css">
<!
font
font
}
</style>
</head>
<body>
<br />
<br />
<table width="
<tr>
<td height="
</tr>
<tr>
<td height="
<br />
內容
</tr>
</table>
<a href="#" target="_blank">版權所有</a>
</body>
</html>
//源碼是替換掉模板中的特征字符
string mbPath = Server
Encoding code = Encoding
StreamReader sr = null;
StreamWriter sw = null;
string str = null;
//讀取
try
{
sr = new StreamReader(mbPath
str = sr
}
catch (Exception ex)
{
throw ex;
}
finally
{
sr
}
//根據時間自動重命名
string fileName = DateTime
str = str
str = str
//生成靜態文件
try
{
sw = new StreamWriter(Server
sw
sw
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw
Response
}
方法二:根據Url地址生成靜態頁保持
思路分析:
直接將做好的動態頁面翻譯成靜態頁面
參考代碼:
//根據Url地址生成靜態頁保持
protected void Button
{
Encoding code = Encoding
StreamReader sr = null;
StreamWriter sw = null;
string str = null;
//讀取遠程路徑
WebRequest temp = WebRequest
WebResponse myTemp = temp
sr = new StreamReader(myTemp
//讀取
try
{
sr = new StreamReader(myTemp
str = sr
}
catch (Exception ex)
{
throw ex;
}
finally
{
sr
}
string fileName = DateTime
//寫入
try
{
sw = new StreamWriter(Server
sw
sw
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw
Response
}
}
From:http://tw.wingwit.com/Article/program/net/201311/14153.html