***************************************************
'Function name: FSOFileRead
'Function: Use FSO to read the file content function
'Parameter: filename ---- file name
'Return value: file content
'************************************************ *
function FSOFileRead(filename)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject(Scripting.FileSystemObject)
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FSOFileRead = objCountFile.ReadAll
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function
'************************************************ *
'Function name: FSOlinedit
'Function: Use FSO to read a certain line of the file function
'Parameter: filename ---- file name
' lineNum ----line number
'Return value: the content of the line in the file
'************************************************ *
function FSOlinedit(filename,lineNum)
if linenum < 1 then exit function
dim fso,f,temparray,tempcnt
set fso = server.CreateObject(scripting.filesystemobject)
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(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
end function
'************************************************ *
'Function name: FSOlinewrite
'Function: Use FSO to write a certain line of the file function
'Parameter: filename ---- file name
' lineNum ---- line number
' Linecontent ---- content
'Return value: None
'************************************************ *
function FSOlinewrite(filename,lineNum,Linecontent)
if linenum < 1 then exit function
dim fso,f,temparray,tempCnt
set fso = server.CreateObject(scripting.filesystemobject)
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
temparray(lineNum-1) = lineContent
end if
tempcnt = join(temparray,chr(13)&chr(10))
set f = fso.createtextfile(server.mappath(filename),true)
f.writetempcnt
end if
f.close
set f = nothing
end function