在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write(AspxToHtml("./admin/Default2.aspx",Server.MapPath("./index.html"))); } /// <summary> /// 将Url放到Path目录下,保存为FileName /// </summary> /// <param name="Url">aspx页面url</param> /// <param name="PathFileName">保存路径和生成html文件名</param> /// <returns></returns> public bool AspxToHtml(string Url, string PathFileName) { try { StringWriter strHTML = new StringWriter(); System.Web.UI.Page myPage = new Page();//System.Web.UI.Page中有个Server对象,我们要利用一下它 myPage.Server.Execute(Url, strHTML);//将asp_net.aspx将在客户段显示的html内容读到了strHTML中 //StreamWriter sw = new StreamWriter(PathFileName, false, System.Text.Encoding.GetEncoding("GB2312")); StreamWriter sw = new StreamWriter(PathFileName, false, System.Text.Encoding.Default); sw.Write(strHTML.ToString());//将strHTML中的字符写到指定的文件中 strHTML.Close(); strHTML.Dispose(); sw.Close(); sw.Dispose(); return true; } catch { return false; } } } 方法B: using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); } protected override void Render(HtmlTextWriter writer) { System.IO.StringWriter html = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter tw = new System.Web.UI.HtmlTextWriter(html); base.Render(tw); System.IO.StreamWriter sw; sw = new System.IO.StreamWriter(Server.MapPath("Default.htm"), false, System.Text.Encoding.Default); sw.Write(html.ToString()); sw.Close(); tw.Close(); Response.Write(html.ToString()); } } |
请发表评论