1、test.asp

<!--#include file="inc/star.asp"-->
<!--#include file="inc/fun.asp"-->
<%
OpenConn
%>
<%
Sql="Select Top 1 ID,title,content,pid From Test Where fabu=0 Order By ID Asc"
Set Rs=Server.CreateObject("ADODB.Recordset")
Rs.Open Sql,Conn,0,1

If Not Rs.Eof Then
 Temp=Temp_Read("temp/test.html") '读取模板
 
 title=Rs("title")
 content=Rs("content")
 
 Temp=Replace(Temp,"$title$",title)
 Temp=Replace(Temp,"$content$",content)
 
 'Response.Write Temp
 
 If CreateHtml("html/a/b/c/"&Rs("pid"),Rs("id")&".html",Temp) Then
  Response.Write "页面:[html/a/b/c/"&Rs("pid")&"/"&Rs("id")&".html]已经生成!"
 End If
 
 Conn.Execute("Update Test Set fabu=1 where ID="&Rs("ID"))
 
 Response.Write("<meta http-equiv=""refresh"" content=""2;url=test.asp"">") '5秒自动刷新页面
Else
 response.write("所有信息文件发布完成!")
End If
%>
<%
CloseConn
%>

 

2、fun.asp

<%
Function Temp_Read(FilePath)
    Dim Fso,textStream
 
    Const ForReading=1
    Const Forwriting=2
    Const ForAppending=8
 
 FilePath=Server.MapPath(FilePath)
 
 Set Fso=Server.CreateObject("Scripting.FileSystemObject")
 
 If Not Fso.FileExists(FilePath) Then
  Response.Write "模板文件"&FilePath&"不存在!"
  Response.End()
 End If
 
    Set textStream=Fso.OpenTextFile(FilePath,ForReading,False)
    If Not textStream.atEndOfStream Then
        Temp_Read=textStream.readall()
    Else
        Response.Write "不能读取模板文件"&FilePath&"或文件为空!"
  Response.End()
    End If
 
    textStream.Close()
 Set Fso=Nothing
End Function

 

Function CreateHtml(FolderPath,FileName,Content)
 Dim Fso,textFile
 
 If Right(FolderPath,1)<>"/" And Right(FolderPath,1)<>"\" Then
  FolderPath=FolderPath&"/"
 End If
 
 FolderPath=Server.MapPath(FolderPath)
 CreateFolders(FolderPath)
 
 FilePath=FolderPath&"\"&FileName
 Set Fso=Server.CreateObject("Scripting.FileSystemObject")
 
 Set TextFile=Fso.CreateTextFile(FilePath,True)
 TextFile.Write(Content)
 
 Set Fso=Nothing
 
 If Err=0 Then
  CreateHtml=True
 Else
  CreateHtml=False
 End If
End Function

 

'建立文件夹(递归)
Function CreateFolders(FolderPath)
 On Error Resume Next
 
 Dim Fso,FolderPaths,i
 
 If Instr(FolderPath,"\")<=0 Or Instr(FolderPath,":")<=0 Then
  CreateFolders=False
  Exit Function
 End If
 
 Set Fso=CreateObject("Scripting.FileSystemObject")
 
 If Fso.FolderExists(FolderPath) Then
  CreateFolders=True
  Exit Function
 End If
 
 FolderPaths=Split(FolderPath,"\")
 FolderPath=""
 
 For i=0 To Ubound(FolderPaths)
  FolderPath=FolderPath&FolderPaths(i)&"\"
 
  If Not Fso.FolderExists(FolderPath) Then
   Fso.CreateFolder(FolderPath)
  End If
 Next
 
 Set Fso=Nothing
 
 If Err=0 Then
  CreateFolders=True
 Else
  CreateFolders=False
 End If
End Function
%>

 

3、temp/test.html

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>$title$</title>
</head>

<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  <tr align="center">
    <td height="30" colspan="5">$title$</td>
  </tr>
  <tr align="center">
    <td height="100" colspan="5" bgcolor="#FFFFFF">$content$</td>
  </tr>
</table>
</body>
</html>