ASP.Net生成静态页面带分页
2011-04-30 23:47
549 查看
模板页
生成代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <div style="width: 417px; height: 54px" align="center"> <br /> Title </div> <div style="width: 417px; height: 8px"> 浏览 <font color="red"> <script src="http://localhost/.Net/NewsFiles/ClickCount.aspx?NewsId=NewsId"> </script> </font>次 Time </div> <div style="width: 417px; height: 100px"> Content </div> <div style="width: 416px; height: 9px"> Pager </div> <div style="width: 416px; height: 8px"> <form id="form1" action="../AddComment.aspx" style="margin: 0px"> <input id="Text1" type="text" /> <img id="Image1" src="http://www.dwww.cn/UserInfo/CheckCode.aspx" /> <br /> <textarea id="CommentContent" cols="20" rows="2"> </textarea> <br /> <input id="NewsId" type="hidden" value="NewsId" /> <input id="Button1" type="submit" value="button" /> <a href="http://www.dwww.cn/News/Display.aspx?NewsId=NewsId">查看更多评论 </a> </form> </div> </body> </html>
生成代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class Add : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string content = "发的发生的方法的是否 的|方式大范德萨费点事的的"; string htmlStr = string.Empty; string[] contentStr = content.Split('|'); string strTable = " <table> <tr> <td>upUrl </td> <td>Number </td> <td>downUrl </td> </tr> </table>";//上下页表格,注意此处的upUrl(上一页),Number(页码分页),downUrl(下一页) int PageNumber = contentStr.Length; for (int m = 0; m <PageNumber; m++) { string numberStr = string.Empty; string filePath=string.Empty; for (int i = 1; i <= PageNumber; i++) { if (i == 1) { numberStr += "[<a href='" + DateTime.Now.ToString("yyyymmddhhmmss") + ".html" + "'>" + i + "</a>]"; } else { int p = i-1; numberStr += "[<a href='" + DateTime.Now.ToString("yyyymmddhhmmss") + "_"+p+".html" + "'>" + i + "</a>]"; } } if (m==0) { filePath = Server.MapPath(".") + "//" + DateTime.Now.ToString("yyyymmddhhmmss") + ".html"; } else { filePath = Server.MapPath(".") + "//" + DateTime.Now.ToString("yyyymmddhhmmss") + "_" + m + ".html"; } using (StreamReader sr = new StreamReader(Server.MapPath("NewsFiles/template.html"),System.Text.Encoding.GetEncoding("gb2312"))) { htmlStr= sr.ReadToEnd(); } htmlStr = htmlStr.Replace("Title", "生成静态页面分页"); htmlStr = htmlStr.Replace("NewsId", "11"); htmlStr = htmlStr.Replace("Time", DateTime.Now.ToString("yyyy/MM/dd")); htmlStr = htmlStr.Replace("Content", contentStr[m]); htmlStr=htmlStr.Replace("Pager", strTable.Replace("Number", numberStr)); FileInfo file=new FileInfo (filePath); Stream fs=file.OpenWrite(); using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"))) { sw.Write(htmlStr); } } } }
相关文章推荐
- Asp.NET生成静态页面并分页
- Asp.NET生成静态页面并分页
- ASP.NET生成静态页面和分页代码
- ASP.NET生成静态页面和分页代码 http://blog.csdn.net/zdyguilong/archive/2007/05/24/1624491.aspx
- Asp.NET 生成静态页面并分页的代码
- Asp.NET生成静态页面并分页
- Asp.net生成静态页面并对内容分页
- Asp.NET 生成静态页面并分页的代码
- Asp.net生成静态页面并对内容分页
- [转]Asp.NET生成静态页面并分页
- Asp.NET生成静态页面并分页
- asp.net生成静态页面后分页
- asp.net生成静态页面及分页
- Asp.NET生成静态页面并分页
- Asp.NET生成静态页面并分页
- Asp.net生成静态页面并直接生成分页的代码实例
- ASP.NET生成静态页面和分页代码
- Asp.NET生成静态页面并分页
- Asp.NET生成静态页面并分页
- Asp.NET生成静态页面并分页