dtm32236
03-21-2008, 12:09 PM
Hi,
I found this very simple asp guestbook (http://www.haneng.com/Lessons_4.asp) and I have a question about the code.
The code is working fine, but there's a line that I don't understand:
MyFile = "c:\guestbook.txt"
I don't get this - where is this file? It's not on my hard drive (i've searched my entire computer for guestbook.txt), so, where can it be? :confused:
The code is simple:
Default.asp:
<form method="post" action="write.asp">
<p><label for="user_name">Name: </label><br><input name="user_name" type="text" size="35"></p>
<p><label for="user_name">Comments: </label><br><textarea rows="10" cols="30" name="new_line"></textarea></p>
<p><input type="submit" value="Post Comment"></p>
</form>
<br><br>
<%
MyFile = "c:\guestbook.txt"
'Opens the guestbook file if it exists
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
IF MyFileObj.FileExists(MyFile) THEN
Set MyTextFile=MyFileObj.OpenTextFile(MyFile)
'Reads a line, and outputs it
WHILE NOT MyTextFile.AtEndOfStream
%>
<hr>
<%=MyTextFile.ReadLine%>
<%
WEND
'Closes the textfile
MyTextFile.Close
END IF' Does file exist
%>
and Write.asp:
MyFile = "c:\guestbook.txt"
'Ready Scripting.FileSystemObject
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
'Opens textfile. 8 = add line to file, true = create if it doesn't exists
Set MyOutStream=MyFileObj.OpenTextFile(MyFile, 8, TRUE)
'Writes the line to the file
New_line = Request.Form("new_line")
New_line = Server.HTMLEncode(New_line)
'Writes the name to the file
User_name = Request.Form("user_name")
User_name = Server.HTMLEncode(User_name)
'Adds the time and date it was posted
New_line = "<I>Posted: " & NOW & "</I><BR>" & New_line
MyOutStream.WriteLine(User_name)
MyOutStream.WriteLine(New_line)
'Closes the file
MyOutStream.Close
'Sends them back to the default page
Response.Redirect "default.asp"
The page I uploaded this to is here:
http://www (dot) foremostgroups (dot) com/dev/2007corporate/default.asp
Can anyone fill me in on this guestbook.txt file? I would really like to know where this is coming from and how I can access it...
Thanks a lot,
Dan
I found this very simple asp guestbook (http://www.haneng.com/Lessons_4.asp) and I have a question about the code.
The code is working fine, but there's a line that I don't understand:
MyFile = "c:\guestbook.txt"
I don't get this - where is this file? It's not on my hard drive (i've searched my entire computer for guestbook.txt), so, where can it be? :confused:
The code is simple:
Default.asp:
<form method="post" action="write.asp">
<p><label for="user_name">Name: </label><br><input name="user_name" type="text" size="35"></p>
<p><label for="user_name">Comments: </label><br><textarea rows="10" cols="30" name="new_line"></textarea></p>
<p><input type="submit" value="Post Comment"></p>
</form>
<br><br>
<%
MyFile = "c:\guestbook.txt"
'Opens the guestbook file if it exists
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
IF MyFileObj.FileExists(MyFile) THEN
Set MyTextFile=MyFileObj.OpenTextFile(MyFile)
'Reads a line, and outputs it
WHILE NOT MyTextFile.AtEndOfStream
%>
<hr>
<%=MyTextFile.ReadLine%>
<%
WEND
'Closes the textfile
MyTextFile.Close
END IF' Does file exist
%>
and Write.asp:
MyFile = "c:\guestbook.txt"
'Ready Scripting.FileSystemObject
Set MyFileObj=Server.CreateObject("Scripting.FileSystemObject")
'Opens textfile. 8 = add line to file, true = create if it doesn't exists
Set MyOutStream=MyFileObj.OpenTextFile(MyFile, 8, TRUE)
'Writes the line to the file
New_line = Request.Form("new_line")
New_line = Server.HTMLEncode(New_line)
'Writes the name to the file
User_name = Request.Form("user_name")
User_name = Server.HTMLEncode(User_name)
'Adds the time and date it was posted
New_line = "<I>Posted: " & NOW & "</I><BR>" & New_line
MyOutStream.WriteLine(User_name)
MyOutStream.WriteLine(New_line)
'Closes the file
MyOutStream.Close
'Sends them back to the default page
Response.Redirect "default.asp"
The page I uploaded this to is here:
http://www (dot) foremostgroups (dot) com/dev/2007corporate/default.asp
Can anyone fill me in on this guestbook.txt file? I would really like to know where this is coming from and how I can access it...
Thanks a lot,
Dan