最近看了很多关于自动生成HTML静态页面的介绍,大多数都使用模板的方法,但模板方式只能应用于一些简单的页面,对于复杂的页面就显示无能为力了,例如页面中有DataList,GridView等控件时,用模板显然解决不了问题,利用页面输出很方便。
public void createHTML()
{
string filePath = Server.MapPath(".") + "index.html";
//调用default.aspx, 并获取其输出
StringWriter sw = new StringWriter();
Server.Execute("Default.aspx", sw);
string content = sw.ToString();
//输出到客户端
Response.Write(content);
Response.Flush();
//写进文件
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
{
using (StreamWriter swrite = new StreamWriter(fs, Response.ContentEncoding))
{
swrite.Write(content);
}
}
}
finally
{
}
}
简单方便
利用页面输出生成HTML静态页面
最新推荐文章于 2021-06-04 01:35:51 发布