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");

前面是一个虚拟地址,而第二个是一个绝对地址

posted on 2009-08-21 15:54  画一个圆圈  阅读(170)  评论(0编辑  收藏  举报

导航