Thứ Tư, 1 tháng 6, 2011

ASP read, write file


function GetFileContent(strFilePath)
strContent = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")

if not fso.FileExists(strFilePath) then
Response.Write("Error: " & strFilePath & " does not exist")
Response.End
end if

Set f=fso.OpenTextFile(strFilePath, 1)

do while f.AtEndOfStream = false
strContent = strContent & f.ReadLine & vbcrlf
'strContent = strContent & "<br />"
loop

GetFileContent = strContent
f.Close
Set f=Nothing
Set fs=Nothing
end function


'*******************************************************************
'
sub WriteFile(strFilePath, strContent)
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile(strFilePath, true)
f.WriteLine(strContent)
f.Close
set f=nothing
set fs=nothing
end sub

1 nhận xét: