如何将动态网页写入到静态页面中??

时间:2022-09-03 20:26:51

这里有我做过的一个例子。

总的思路是,先写到一个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();