1. 首頁
  2. »
  3. 網頁開發
  4. »
  5. ASP.NET
  6. »
  7. [.NET]aspx動態網頁轉成html靜態網頁

[.NET]aspx動態網頁轉成html靜態網頁

2008/12/20
aspx2html protected void Page_Load(object sender, EventArgs e) { // 前為來源檔案,後為輸出檔案 transHtml("show.aspx", "show.htm"); } public void transHtml(string path, string outpath) { System.Web.UI.Page page = new Page(); StringWriter writer = new StringWriter(); page.Server.Execute(path, writer); FileStream fs; fs = File.Create(page.Server.MapPath("") + "\\" + outpath); byte[] bt = System.Text.Encoding.Default.GetBytes(writer.ToString()); fs.Write(bt, 0, bt.Length); fs.Close(); Response.Write("寫入成功"); } ※須將網站的目錄權限開啟為寫入。 [範例下載]

aspx2html
protected void Page_Load(object sender, EventArgs e)
{
// 前為來源檔案,後為輸出檔案
transHtml("show.aspx", "show.htm");
}

public void transHtml(string path, string outpath)
{
System.Web.UI.Page page = new Page();
StringWriter writer = new StringWriter();
page.Server.Execute(path, writer);

FileStream fs;

fs = File.Create(page.Server.MapPath("") + "\\" + outpath);
byte[] bt = System.Text.Encoding.Default.GetBytes(writer.ToString());
fs.Write(bt, 0, bt.Length);
fs.Close();

Response.Write("寫入成功");
}

※須將網站的目錄權限開啟為寫入。


[範例下載]