如何將動態網頁寫入到靜態頁面中??

這裏有我做過的一個例子。

總的思路是,先寫到一個streamBuilder中。再把streamBuilder的對象寫進靜態網頁中。

System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("<table width=/"251/" border=/"0/" cellspacing=/"0/" cellpadding=/"0/">/r/n");
    sb.Append("  <tr>/r/n");
    sb.Append("    <td width=/"174/" background=/"images/06517blog_37.jpg/"><img src=/"images/06517blog_19.jpg/" width=/"98/" height=/"28/"></td>/r/n");
    sb.Append("    <td width=/"77/" background=/"images/06517blog_37.jpg/">&nbsp;</td>/r/n");
    sb.Append("  </tr>/r/n");
    for(int i=0;i<dt.Rows.Count;i++)
    {
     sb.Append("<tr>/r/n");
     sb.Append("   <td height=/"23/">·" + appCode.myCommon.getLinkByTitleAndID(dt.Rows[i]["title"],dt.Rows[i]["ID"]) + "</td>/r/n");
     sb.Append("   <td height=/"23/"><span class=/"kbblog_wd16/">" + appCode.myCommon.getLinkByNickNameAndAssID(dt.Rows[i]["nickName"],dt.Rows[i]["authorID"]) + "</span></td>/r/n");
     sb.Append("</tr>/r/n");
    }
    sb.Append("<tr>/r/n");
    sb.Append("  <td height=/"15/" colspan=/"2/">&nbsp;</td>/r/n");
    sb.Append("</tr>/r/n");
    sb.Append("</table>/r/n");

    if(!System.IO.Directory.Exists(Server.MapPath("blogAdmin/html")))
    {
     System.IO.Directory.CreateDirectory(Server.MapPath("blogAdmin/html"));
    }
    System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("html/thehot.htm"),false,System.Text.Encoding.GetEncoding("gb2312"));
    sw.Write(sb.ToString());
    sw.Close();

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