Asp与.net分页生成静态代码

今天又学到了两个函数代码,都是关于分页静态生成的(一个是ASP,一个是.NET),很不错的说。我想再研究研究,看是否能应用到ZB中去,实现Z-Blog分页的静态化。可以的话,肯定是一件功德无量的事情呵,大家为我加油吧!
1.Asp分页生成静态代码
<!--#include file="conn.ASP"-->
<%
strHead=strHead&"<html>"
strHead=strHead&"<head>"
strHead=strHead&"<TITLE>Asp分页生成静态</TITLE>"
strHead=strHead&"<LINK href=""inc/style.css"" type=text/css rel=stylesheet>"
strHead=strHead&"</head>"
%><%
sql="select * from news"
set rs=server.createObject("ADODB.Recordset")
rs.open sql,conn,1,1
%><%
rs.pagesize=2
totalpage=rs.pagecount
rs.close
set rs=nothingfor j=1 to totalpage
sql="select * from news"
set rs=server.createObject("ADODB.Recordset")
rs.open sql,conn,1,1whichpage=j
rs.pagesize=2
totalpage=rs.pagecount
rs.absolutepage=whichpage
howmanyrecs=0
%><%
str0=""
str0=str0&"</p>"
str0=str0&"<table bgcolor=#cecfce align=center border=0 width=800 cellpadding=2 cellspacing=1>"
%><%
do while not rs.eof and howmanyrecs<rs.pagesize
%><%
str0=str0&"<tr bgcolor=#f7f7f7>"
str0=str0&"<td bgcolor=#f7f7f7 align=""center"">"&rs(0)&"</td>"
str0=str0&"<td bgcolor=#f7f7f7 align=""center"">"&rs(1)&"</td>"
str0=str0&"<td bgcolor=#f7f7f7 align=""center"">"&rs(2)&"</td>"
str0=str0&"<td bgcolor=#f7f7f7 align=""center"">"&rs(3)&"</td>"
str0=str0&"</tr>"
%><%
rs.movenext
howmanyrecs=howmanyrecs+1
loop
rs.close
set rs=nothing
%><%str0=str0&"</table>"%>
<%
'分页部分
ref=""ref=ref&"<br>"
ref=ref&"<table bgcolor=#cecfce align=center border=0 width=800 cellpadding=0 cellspacing=1> "
ref=ref&"<tr bgcolor=#f7f7f7>"
ref=ref&"<td> "
ref=ref&"<b>Pages: " & j & " / " & totalpage &"</b>"
ref=ref&"</td>"
ref=ref&"<td> "ref=ref&"<a href=list_1.html"&">" & "<FONT face=Webdings>9</FONT>" & "</a> "
if whichpage=1 then
ref=ref&"<FONT face=Webdings>7</FONT>"
else
ref=ref&"<a href=list_"&j-1&".html"&">" & "<FONT face=Webdings>7</FONT>" & "</a> "
end iffor counter=1 to totalpage
ref=ref&"<a href=list_"&counter&".html"&">[" & counter & "]</a>"
ref=ref& " "
if counter mod 10 = 0 then
ref=ref& "<br>"end if
nextif (whichpage>totalpage or whichpage=totalpage) then
ref=ref&"<FONT face=Webdings>8</FONT>"
else
ref=ref&"<a href=list_"&j+1&".html"&">" & "<FONT face=Webdings>8</FONT>" & "</a> "
end if
ref=ref&"<a href=list_"&totalpage&".html"&">" & "<FONT face=Webdings>:</FONT>" & "</a> "Dim fso,f
Dim strTitle,strContent,strOut
'创建文件系统对象
Set fso=Server.createObject("Scripting.FileSystemObject")
Set f=fso.createTextFile(Server.MapPath("list_"&j&".html"),true)'写入网页内容
f.WriteLine strHead&str0&ref
f.close
response.write "正在生成第"&j&"个页面!<br>"
next
%>
2.Asp.net分页生成静态代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
WriteFile("低一度专题", "低一度真棒!<br/>", "2", "2.html");
}
public void WriteFile(string strText, string content, string page, string name)
...{
string path = HttpContext.Current.Server.MapPath("news/get");
System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312");
// 读取模板文件
string temp = HttpContext.Current.Server.MapPath("news/text.htm");
StreamReader sr = null;
StreamWriter sw = null;
string str = "";
try
...{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
}
catch (Exception exp)
...{
HttpContext.Current.Response.Write(exp.Message);
HttpContext.Current.Response.End();
sr.Close();
}
string htmlfilename = name.ToString();
// 替换内容
// 这时,模板文件已经读入到名称为str的变量中了
str = str.Replace("$title", strText); //模板页中的$title,即标题
str = str.Replace("$content", content);//模板页中的$content,即内容
str = str.Replace("$page", page);//模板页中的$page,即页码连接格式
// 写文件
try
...{
sw = new StreamWriter(path + "/" + htmlfilename, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
...{
HttpContext.Current.Response.Write(ex.Message);
HttpContext.Current.Response.End();
}
finally
...{
sw.Close();
}
}
}
本文出自:低一度,地址:http://www.diyidu.cn/post/pagebar_better.html,转载须注明!

我只能看懂那么一点点,祝愿您能成功。
呵呵,桶哥,等着你来造福ZBloger了。