Hi all,
I'm a novice asp coder. I've got a web page that have a <textarea> that I need to populate with what is in a text file. For now, I just want to Read the text file into the textarea, but I just can't seem to get it to work. Here's what I've got:
and here is the html
and yeah, I would like to leave this as a function if at all possible (due for many reasons, but primarily because that's the style already existing in many many asp pages at our company and no direction to change it).
I've tried response.writting the data1 and data2 out within the do while loop as well as right after calling the function in the textarea by doing a for x = 1 to counter. nothing seems to work (no data displayed in the textarea).
Thanks for any help.
I'm a novice asp coder. I've got a web page that have a <textarea> that I need to populate with what is in a text file. For now, I just want to Read the text file into the textarea, but I just can't seem to get it to work. Here's what I've got:
Code:
Function getFile(fileThis)
dim Filename
Filename = "someFile.txt"
'format is data1|data2
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
' Create a filesystem object
Dim fso
set fso = server.createObject("Scripting.FileSystemObject")
' Map the logical path to the physical system path
Dim Filepath
Filepath = Server.MapPath(Filename)
if fso.FileExists(Filepath) Then
' Get a handle to the file
Dim file, Line
set file = fso.GetFile(Filepath)
' Open the file
Dim TextStream
Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault)
' Read the file line by line
dim counter, UserID(), PW()
counter = 1
Do While Not TextStream.AtEndOfStream
Line = TextStream.readline
arrayFile = split(Line,"|")
data1(counter) = arrayFile(0)
data2(counter) = arrayFile(1)
counter = counter + 1
Loop
Set TextStream = nothing
Else
Response.Write("<font size=2 color=red>Users file not found on server</font><br>" & Filename)
End If
End Function
Code:
<textarea name="somename" cols="30" rows="15">
<% Thisfile = getFile(fileThis) %>
</textarea>
I've tried response.writting the data1 and data2 out within the do while loop as well as right after calling the function in the textarea by doing a for x = 1 to counter. nothing seems to work (no data displayed in the textarea).
Thanks for any help.