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