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("寫入成功");
}
※須將網站的目錄權限開啟為寫入。
[範例下載]