2012-10-30 15:33:05| 分类: ASP.NET WEB | 标签: |举报 |字号大中小 订阅
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 AspxToHtml: System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected override void Render(HtmlTextWriter writer){TextWriter tw = new StringWriter();base.Render(new HtmlTextWriter(tw));tw.Close();string html = tw.ToString();//设定本次生成的静态页面的名字string strFileName = Server.MapPath(".") + "/" + "html1.html";//调用文件写出方法ToHtml(strFileName, html);}public static void ToHtml(string filmname, string html){System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312"); //指定一个gb2312的中文编码string htmlfilename = filmname;string str = html;StreamWriter sw = null;try{sw = new StreamWriter(htmlfilename, false, code);sw.Write(str);sw.Flush();}catch (Exception ex){HttpContext.Current.Response.Write(ex.Message);HttpContext.Current.Response.End();}finally{sw.Close();}}}
评论