2013年2月21日 星期四

C# 如何將ASP 執行結果自動存成一個HTML檔


將ASP動態網頁的 執行結果 存成一個HTML檔

From http://www.blueshop.com.tw/board/show.asp?subcde=BRD20100401103944GOG



using System.Text;
using System.IO;





    protected override void Render(HtmlTextWriter writer)
    {
        Encoding enc = Encoding.GetEncoding("utf-8");
        string strToDay = DateTime.Now.ToString("yyyyMMdd");
        Guid g = Guid.NewGuid();
        //string fileName = "exp_" + strToDay + ".html";
        //string pathFileName = Server.MapPath(fileName);
        String sFile = @"C:\Test Temp\" + g.ToString() + ".html";

        StringBuilder sb = new StringBuilder();
        if (!File.Exists(sFile))
        {
            StringWriter sw = new StringWriter(sb);
            writer = new HtmlTextWriter(sw);
            base.Render(writer);

            using (StreamWriter swLog = new StreamWriter(sFile, false, enc))
            {
                swLog.WriteLine(sb.ToString());
                swLog.Close();
            }

            Response.Write(sb.ToString());
        }
        else
        {
            Server.Transfer(sFile);
        }
    }//




繼承 Render 事件

http://www.cnblogs.com/skynet/archive/2010/04/29/1724020.html

0 意見:

張貼留言

 

MangoHost Copyright © 2009 Cookiez is Designed by Ipietoon for Free Blogger Template