Simple Guestbook Question

Discussion in 'C#' started by dtm32236, Mar 21, 2008.

  1. #1
    Hi,

    I found this very simple asp guestbook 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?

    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="27" 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
        %>
    <div style="padding:8px; margin:10px 0; border-bottom:1px solid #666;">
     <%=MyTextFile.ReadLine%>
    </div>
        <%
        WEND
    
        'Closes the textfile
        MyTextFile.Close
      END IF' Does file exist
    %>
    Code (markup):
    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"
    Code (markup):
    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 for any help.
     
    dtm32236, Mar 21, 2008 IP
  2. gsxraddict

    gsxraddict Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    MyFile = "c:\guestbook.txt"

    You can change that line, they are saving to a textfile appending instead of to a database or something. Create the guestbook.txt, or create a guestbook.txt and upload it to your webserver.

    MyFile = Server.MapPath("guestbook.txt")


    This is a really old school example.
     
    gsxraddict, Mar 21, 2008 IP
  3. dtm32236

    dtm32236 Guest

    Messages:
    320
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i think that i'm going to have to use a database...

    Basically, I have this page to look up local toilet rebate programs and I want users to be able to discuss this, or post new links if they know of one we're missing. But I want a separate guestbook for each state. It seems like it's going to be a little complicated, so I thought I'd get some ideas - maybe there's a better way I could do this.

    PS - we don't have PHP support.
     
    dtm32236, Mar 24, 2008 IP
  4. dtm32236

    dtm32236 Guest

    Messages:
    320
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Okay, so I got this working the way I want (the simple way using the .txt files - I didn't want to get into databases, cause that would take too long to teach myself). Anyway, one more simple question:

    I have the form execute, and it works perfectly:

    <form method="post" action="write.asp">
            <p><input type="hidden" name="state" value="AK"></p>
            <p><label for="user_name">Name: </label><br><input name="user_name" type="text" size="35"><input type="text" name="info" alt="special" class="special"></p>
            <p><label for="user_name">Comments: </label><br><textarea rows="3" cols="27" name="new_line" style="border:1px solid #ccc;"></textarea></p>
            <p><input type="submit" value="Post Comment"></p>
            </form>
            <br>
            <% 
    		  MyFile = "c:\alaska.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 %>
                  <p class="post"><%=MyTextFile.ReadLine%></p>
    			<% WEND
                'Closes the textfile
                MyTextFile.Close
              END IF' Does file exist 
    		%>
    <!-- JavaScript Code here -->
    Code (markup):
    but now, I'd like it to trigger a JavaScript function afterwards. The function is "togLayer('AK'); return false". Does anyone know how I can make this execute (it's no onclick or anything, i'm hoping to make it automatic). Does that make sense?

    Thanks a lot guys.
     
    dtm32236, Mar 25, 2008 IP
  5. dtm32236

    dtm32236 Guest

    Messages:
    320
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    nevermind... everything works great!

    doing

    <script type="text/javascript">
    togLayer('AK');
    </script>

    worked perfectly.

    thanks for your help gsxraddict.
     
    dtm32236, Mar 25, 2008 IP