快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

FSO的几个应用函数

 1,读取文件中所有字符的函数

Function FSOFileRead(filename)
filename = Server.mappath(filename)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.fileExists(filename) then exit function
Set cnrs = fso.OpenTextFile(filename,1)
While Not cnrs.AtEndOfStream
rsline = cnrs.ReadLine
rsline = server.HTMLEncode(rsline)
Response.Write(rsline & "<br>")
Wend
end Function

  其实就是通过ReadLine(读取行),通过 While Not cnrs.AtEndOfStream 的条件进行循环读取行,来达到读取文件中所有字符。当然也可以使用ReadAll代替多个ReadLine,但主要缺点是将格式进行换行等问题需要再次解决。

  引用函数 call FSOFileRead("xxx文件") 即可

  2,读取文件中某一行中所有字符的函数

Function FSOlinedit(filename,lineNum)
if linenum < 1 then exit function
filename = Server.mappath(filename)
set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.fileExists(filename) then exit function
set f = fso.opentextfile(filename,1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
FSOlinedit = temparray(lineNum-1)
end if
end if
Response.Write(FSOlinedit)
end Function

  这次即使用了readall方式,通过split函数将读取的内容以换行为条件,进行数组的定义,提取 lineNum-1(数组从0记数) 所对应的数组值即为 读取的该行值 ,也就是该行中所有的字符了。

  函数的调用 call FSOlinedit("xxx文件",35) 表示显示xxx文件的第35行内容

  3,读取文件中最后一行内容的函数

Function FSOlastline(filename)
filename = Server.mappath(filename)
set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.fileExists(filename) then exit function
set f = fso.opentextfile(filename,1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
FSOlastline = temparray(ubound(temparray))
end if
Response.Write(FSOlastline)
end function

  其实和读取某一行的函数类似,主要即是 数组的上界ubound值 就是最末的值 ,故为最后一行。函数的引用也很简朴。
返回类别: 教程
上一教程: 页顶导航条示例
下一教程: 用XMLHTTP POST/GET HTML页面时的中文乱码之完全SCRIPT解决方案

您可以阅读与"FSO的几个应用函数"相关的教程:
· ASP应用中的应用函数
· 关于session的几个补充函数
· 格式化数字函数FORMATNUMBER的应用
· 影响IIS性能的几个因素(3)
· ASP.NET中处理datetime的一些通用函数
    微笑服务 优质保证 索取样品