asp (visual basic script) read data from file none of these 3 programs work. I don't understand why <% Dim fso, f, s Set fso = CreateObject("Scripting.FileSystemObject") Set f = fspenTextFile("c:\testfile.txt", 1) s = f.ReadAll strInputSearch=s response.write(strInputSearch) s.Close %> -------------------------------------------------------------------------------- <% Dim FSO, File, TextStream, S Set File = FSO.GetFile("c:\testfile.txt") Set TextStream = File.OpenAsTextStream(OpenFileForReading) Do While Not TextStream.AtEndOfStream S = S & TextStream.ReadLine & NewLine Loop TextStream.Close response.write(S) %> -------------------------------------------------------------------------------- <% Dim FSO, TextStream, S Set TextStream = FSO.OpenTextFile("<% Dim FSO, TextStream, S Set TextStream = FSO.OpenTextFile("c:\testfile.txt", OpenFileForReading) <A NAME="closereadfromfile"></A> S = TextStream.ReadAll & NewLine & NewLine TextStream.Close response.write(S) %> -------------------------------------------------------------------------------- this program, that writes into a file, works Dim fso, MyFile Set fso = CreateObject("Scripting.FileSystemObject") Set MyFile= fspenTextFile("c:\testfile.txt", 2) MyFile.WriteLine(strInputSearch) MyFile.Close
try: <%const forreading = 1 const tristateusedefault = -2 Dim FSO, TextStream, S set FSO = server.createobject("Scripting.FileSystemObject") Set FSO = CreateObject("Scripting.FileSystemObject") Set TextStream = FSO.opentextfile("c:\testfile.txt",forreading, tristateusedefault) %> <A NAME="closereadfromfile"></A><% S = TextStream.ReadAll & NewLine & NewLine TextStream.Close response.write(S) %> Code (markup): FSO opentextfile is picky about arguments. Plis, I've cleaned up your code a bit - it's basically the second example, except that you don't define FSO, and you don't escape codespace for the anchor html code.
To use this type of constants you must include "adovbs.inc" file. You can also virutual include. The file defines all the constant like OpenFileForReading ...... You may found in your computer just search on your PC.