Monday, December 17, 2007

How to open a text file on the web server and read it

How to open a text file on the web server and read it

S T E P - 1

- We need to use the FileSystemObject object:

<%

Const ForReading = 1, ForAppending = 8 'Set the iomode

Dim fSys, f

Set fSys = CreateObject("Scripting.FileSystemObject")

%>

S T E P - 2

- Now, we need to get the web server's current folder.

- We can use the server.mappath(".") to get it.

- So, we can open the text file in the web server using OpenTextFile method.

<%

Set objOpenFile = fSys.OpenTextFile(server.mappath(".") & "\myFile.txt", ForReading)

Response.write(objOpenFile.ReadAll)

Set fSys = Nothing

%>

No comments: