How to open a text file on the web server and write data into this file (Using TextStream)
S T E P - 1
- We need to use the FileSystemObject object:
<%
Const ForReading = 1, ForAppending = 8 'Set the iomode
Dim fSys, objF, objText
Set fSys = CreateObject("Scripting.FileSystemObject")
%>
S T E P - 2
- We can use the server.mappath(".") to get the webserver's current folder.
- After that, use the GetFile method to get a File Object.
<%
Set objF = fSys.GetFile(server.mappath(".") & "\myFile.txt")
Set objText = objF.OpenAsTextStream(ForAppending, 0)
'0 = Using ASCII format
'-1 = Using Unicode format
'-2 = Using system default format
objText.writeLine("Hello Word")
objText.Close
Set objF = Nothing
Set fSys = Nothing
%>
No comments:
Post a Comment