用户操作
[即时聊天] [发私信] [加为好友]
流氓蚊子ID:zhanghongwen
1147次访问,排名2万外好友6人,关注者13
zhanghongwen的文章
原创 4 篇
翻译 0 篇
转载 0 篇
评论 24 篇
最近评论
文章分类
    收藏
    相册
    视频照.
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 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
    %> 

    发表于 @ 2006年08月23日 17:12:00|评论(loading...)|编辑

    新一篇: 数据库操作通用代码! | 旧一篇: 远程下载图片!

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 流氓蚊子