生成靜態頁面

1、寫靜態網頁要先創建一個模板,在WebSet目錄下創建Template,然後創建一個

html網頁,標明title,Content,Data等。點擊WebSet網站點屬性把虛擬路徑改成

\
2、在BLL層寫一個創建文件的方法
需要引用System.IO和System.Web
 static void CreateFile(string title, string content, string date,

string filename)
        {
            string path = HttpContext.Current.Server.MapPath

("Template/Aritcle.html");//獲得模板頁的路徑
            string openfile = File.ReadAllText(path, Encoding.UTF8);
//用string類型的變量接受文件的所有行
            string str = openfile.Replace("{Title}", title);
            str = str.Replace("{Content}", content);
            str = str.Replace("{Date}", date);

            string createpaht = HttpContext.Current.Server.MapPath

("Article") + "\\" + filename;//新網頁的地址

            using (StreamWriter sw = File.AppendText(createpaht))
            {
                sw.Write(str);
                sw.Close();
            }
        }
3、創建一個文件夾存放生成的靜態網頁
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章