NET下将aspx转换成为html静态页面
public bool ExecAspxToHtml(string Url,string Path,string FileName)
{
try
{
StringWriter strHTML=new StringWriter();
System.Web.UI.Page myPage=new Page();
myPage.Server.Execute(Url,strHTML);
StreamWriter sw=new StreamWriter(Path+FileName,false,System.Text.Encoding.GetEncoding("gb2312"));
sw.Write(strHTML.ToString());
strHTML.Close();
sw.Close();
//myPage.Response.Write(strHTML.ToString());
return true;
}
catch{return false;}
}
在调用时须注意一下:aspx.ExecAspxToHtml("~/test.aspx", Server.MapPath(@"~/images/"), "111.htm");
前面是一个虚拟地址,而第二个是一个绝对地址