无限分类生成HTML文件

本文介绍了一种通过递归查询数据库获取文章分类信息,并根据分类深度及路径生成对应的HTML文件的方法。具体包括如何构建文件路径、创建文件夹及生成文件内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

'无限分类生成HTML文件


'接收传递过来的文章路径参数

set rsHtmlFileCode=server.CreateObject ("ADODB.RecordSet")
sql4="select * from Article where ID="&CurrentArticleID
rsHtmlFileCode.Open sql4,conn,1,3
if rsHtmlFileCode.EOF and rsHtmlFileCode.bof then
response.Write("alert('没有找到需要生成HTML的文章数据内容');history.go(-1);")
response.End()
else

ClassDepth=rs("ClassDepth")
ClassID=rs("ClassID")
ParentID=rs("ParentID")
'获取当前文章路径
if ClassDepth=0 then
CurrentClassDir="/"&sClassDir
else
sClassDepth=ClassDepth-1
sParentID=ParentID
CurrentClassDir=""
GetCurrentClassDirPath sClassDepth,sParentID,CurrentClassDir
end if
'建立当前文章目录
CreatHtmlFolder CurrentClassDir

end if
rsHtmlFileCode.close
set rsHtmlFileCode=nothing

'获取文章对应的静态生成页面文件路径
Function GetCurrentClassDirPath(CurrentClassDepth,CurrentClassID,CurrentClassDir)

set rsClsssDirPath=server.CreateObject ("ADODB.RecordSet")
sqlClsssDirPath="select * from ArticleClass where ParentID="&CurrentClassID
rsClsssDirPath.Open sqlClsssDirPath,conn,1,3
if rsClsssDirPath.EOF and rsClsssDirPath.bof then
response.Write("alert('没有找到需要生成HTML的文章数据内容');history.go(-1);")
response.End()
else

sClassDepth=rsClsssDirPath("ClassDepth")-1
sParentID=rsClsssDirPath("ParentID")
sClassDir=rsClsssDirPath("ClassDir")

if sClassDepth=0 then

if CurrentClassDir="" then
'当前文章的类别是顶类下的文章的路径
StrClassDir="/"&sClassDir
else
'多级类别下的文章的路径
StrClassDir=sClassDir&"/"&CurrentClassDir
end if
Exit Function
else
CurrentClassDir=sClassDir&"/"&CurrentClassDir
GetCurrentClassDirPath sClassDepth,sParentID,CurrentClassDir
end if
end if
rsClsssDirPath.close
set rsClsssDirPath=nothing

end Function

'建立对应的文件夹
Function CreatHtmlFolder(CurrentFolderName)
CurrentFolderPath=Server.MapPath(CurrentFolderName)
Set FolderObject=Server.CreateObject("Scripting.FileSystemObject")
if not FolderObject.FolderExists(CurrentFolderPath) then
FolderObject.CreateFolder(CurrentFolderPath)
response.Write(CurrentFolderPath&"文件夹创建完成")
else
response.Write(CurrentFolderPath&"文件夹已存在")
end if
set FolderObject=nothing
end Function

'建立对应的文件内容
Function CreatHtmlFile(ClassDirPath,FileName,FileExt,ArticleID,HtmlContentCode)
Set fso = CreateObject("scripting.FileSystemObject")
HtmlFileName=ClassDirPath&"/"&HtmlFileName&"."&HtmlFileExt
HtmlFileNamePath=Server.MapPath(HtmlFileNamePath)
Set ObjHtmlFile=fso.OpenTextFile(HtmlFileNamePath,8,True)

ObjHtmlFile.WriteLine HtmlContentCode

ObjHtmlFile.Close
Set ObjHtmlFile=Nothing
end Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值