XMLHTTP生成静态文件!

<%
'=============================文件生成相关配置 开始====================================
dim sitepath,homepath,newspath,newslist
sitepath = Server.MapPath("/")
homepath = sitepath&"/html/home/"
newspath = sitepath&"/html/news/"
newslistpath = sitepath&"/html/newslist/"
'=============================文件生成相关配置 结束====================================
function makefile(filetype)
 sitepath = Server.MapPath("/")
 select case filetype
 case "1"
  '首页文件
  template = sitepath&"/html/temp/home.shtml"
  filename = sitepath&"/html/home/"
 case "2"
  '新闻列表及分页
  template = sitepath&"/html/temp/newslist.shtml"
  filename = sitepath&"/html/newslist/list"&classid&"_"&pageNo&".shtml"
 case "3"
  '新闻显示页面
  template = sitepath&"/html/temp/news.shtml"  
 end select
 Set fso = Server.CreateObject("Scripting.FileSystemObject")
 '读取模板的内容
 Set ftemp=fso.OpenTextFile(template, 1)
 pencat = ftemp.ReadAll
 ftemp.Close
 'response.write(bigclassID)
 'response.end
 '替换掉里面的内容
 if pagetitle="" or isnull(pagetitle) then pagetitle = title&"---中国电子信息教育网"  end if
  pencat=replace(pencat,"@pagetitle",pagetitle)
  pencat=replace(pencat,"@title",title)
  pencat=replace(pencat,"@Content",Content)
  pencat=replace(pencat,"@addtime",addtime)
  pencat=replace(pencat,"@Source",StrSource)
  pencat=replace(pencat,"@Author",Author)
  
  pencat = replace(pencat,"@bclass",bigclassname)
  pencat = replace(pencat,"@list.html","list_"&bigclassID&".shtml")
  pencat = replace(pencat,"@add_bclass","<a href=""/html/Column/Column_"&bigclassID&".shtml"">"&bigclassname&"</a>")
  pencat = replace(pencat,"@add_sclass","<a href=""/html/newslist/list"&SmallClassID&"_1.shtml"">"&smallclassname&"</a>")

       newspath=""
       newspath=sitepath&"/html/news/"&year(now())&"/"
       
   If NOT fso.folderexists(newspath) then
          fso.createfolder(newspath)
    newspath=sitepath&"/html/news/"&year(now())&"/"&month(now())&"/"       
          fso.createfolder(newspath)
    filename=newspath&"/newsview"&makefilename(addtime)&".shtml"         
   else
        newspath=sitepath&"/html/news/"&year(now())&"/"&month(now())&"/"  
        If NOT fso.folderexists(newspath) then
         fso.createfolder(newspath)
   filename=newspath&"/newsview"&makefilename(addtime)&".shtml"
  else
   filename=newspath&"/newsview"&makefilename(addtime)&".shtml"
  end if
   end if 
    
    Set fout = fso.CreateTextFile(filename)
    fout.WriteLine pencat
    fout.close
    Set fso = nothing
    '--------------------查检文件生成过程中是否产生错误-------------------
    if Err.Number>0 then
    makefile = "<div><b>生成不成功:</b></div><div>文件:<font color=""#0000FF"">"&filename&"</font></div><div>产生错误的原因可能为:"&CStr(Err.Description)&"</div><div>错误代码:"&CStr(Err.Number)& "</div>"
     else
    makefile = "<div><b>生成成功:</b></div><div>文件:<font color=""#0000FF"">"&filename&"</font></div>"
    end if
       Err.clear() 
end function

function makefilename(datestr)
 dim getfilename,str
 str = Cdate(datestr)
 getfilename = year(str)
 getfilename = getfilename&right("00"&month(str),2)
 getfilename = getfilename&right("00"&day(str),2)
 getfilename = getfilename&right("00"&hour( str),2)
 getfilename = getfilename&right("00"&minute(str),2)
 getfilename = getfilename&right("00"&Second(str),2)
 makefilename = Cstr(getfilename)
end function
Function SaveFile(fileBody,filePath)
 'fileBody ---- 要写入文件的内容(字符串)
 'filePath ---- 要生成文件的路径(绝对地址加文件名)
 '-------------------------本函数为将流内容存盘的函数------------------
 On Error Resume Next
 Set objStream = Server.CreateObject("ADODB.Stream")
 '--------------建立ADODB.Stream对象,必须要ADO 2.5以上版本------------
 objStream.Type = 2
 objStream.CharSet="gb2312"
 '-------------以文本模式打开------------------------------------------
 objStream.Open
 objstream.WriteText fileBody,1
 '--------------------将字符串内容写入文件-----------------------------
 '路径注意
 objstream.SaveToFile filePath,2
 '-----------------------关闭对象,释放资源----------------------------
 objstream.Close()
 set objstream = nothing
 '--------------------查检文件生成过程中是否产生错误-------------------
 if Err.Number>0 then
  SaveFile = "<div><b>生成不成功:</b></div><div>文件:<font color=""#0000FF"">"&filePath&"</font></div><div>产生错误的原因可能为:"&CStr(Err.Description)&"</div><div>错误代码:"&CStr(Err.Number)& "</div>"
 else
  SaveFile = "<div><b>生成成功:</b></div><div>文件:<font color=""#0000FF"">"&filePath&"</font></div>"
 end if
 Err.clear()
End Function
%> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值