Using the
File System Object
to
Read from a File
:
Click here to test this script.
Code:
Place in the <BODY>:
Highlight
<% Dim Filepath, Contents, TextStream Const ForReading = 1, ForWriting = 2, ForAppending = 3 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 set fso = server.createObject("Scripting.FileSystemObject") Filepath = server.MapPath("./" & "test.txt") if fso.FileExists(Filepath) then Set TextStream = fso.OpenTextFile(Filepath, ForReading, False, TristateUseDefault) Contents = TextStream.ReadAll Response.write (Contents) TextStream.Close set TextStream = nothing end if set fso = nothing %>