技术文档
编程杂记
友情链接
技术文档 >ASP.NET >
从Discuz!NT v2.0扣出来的生成静态页面的方法
2008-8-9 11:48:25 浏览/评论:245/2
asp.net下生成静态页的方法有很多,目前我尝试过的方法4-5种,前几天在看Discuz!NT v2.0的源码时,发现了下面的代码。原理很简单,不啰唆了,直接看代码好了:

/**//// <summary>
/// 转换为静态html
/// </summary>
public void transHtml(string path,string outpath) 
...{
Page page = new Page();
StringWriter writer = new StringWriter();
page.Server.Execute(path, writer);
FileStream fs;
if(File.Exists(page.Server.MapPath("") + "\" + outpath)) 
...{
File.Delete(page.Server.MapPath("") + "\" + outpath);
fs = File.Create(page.Server.MapPath("") + "\" + outpath);
}
else 
...{
fs = File.Create(page.Server.MapPath("") + "\" + outpath);
}
byte[] bt = Encoding.Default.GetBytes(writer.ToString());
fs.Write(bt,0,bt.Length);
fs.Close();
}网友评论
11(浙江省温州市电信:60.190.*.*)于 2008-8-13 17:44:31 发布评论:
111
22(浙江省杭州市电信:122.224.*.*)于 2008-8-18 15:42:52 发布评论:
good