When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Thursday, June 29, 2000

Creating a Guestbook, Part 2

By Joshua Bengal

  • Read Part 1

  • In Part 1 we looked at the source code for AddGuest.html and Submit.asp, two Web pages that allowed users to add a new guestbook entry. In this part we will examine Guestbook.asp, the ASP page that displays the guestbook in its entirity.

    - continued -

    This file contains the header of our guestbook page (you know, that cheezy text we all love to put there, as well as any banners and titles we may want) and then writes out the contents of entries.dat. Note: If you wanted to make a nifty little "View my guestbook" link so people could see the entries without signing in, you would link it to this file.

    By now we should all be experts at basic file manipulation, so I'll just put this code here without explanation and see if you can handle it.

    Option Explicit
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    'declare variable
    Dim objFS, objFile, objFile2, entries, textstream
    'read guestbook entries into textstream
    Set objFS = Server.CreateObject ("Scripting.FileSystemObject")
    set objFile = objFS.GetFile(server.mappath("entries.dat"))
    set textstream = objFile.OpenAsTextStream(ForReading, -2)
    entries = textstream.ReadAll
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <body bgcolor=#000000 text=#FFFFFF link=#FFFFCC vlink=#FFFFCC alink=#FF0000>
    <font face=Verdana size=5> Guestbook </font>
    <font face=Verdana size=2><blockquote>
    <% response.write(entries) %>

    And there you have it, your own little ASP guestbook. In real life, I made mine a little more complex (I check to see if URL and email were entered, and if they were I linked the names and email address to them) but this is pretty much the basic idea. And stick my name (Joshua Bengal, for those who don't notice author's) somewhere in the code so I can feel proud.

    To see this guestbook in action, swing on over to http://www.joshuabengal.com and sign my guestbook. Have fun! If you have any questions/comments/praise/money, feel free to write me at emkorial@home.com.

    Happy Programming!

    Related Articles

  • View the Guestbook in Action!
  • Read the FileSystemObject F.A.Q.
  • Another "Create a Guestbook" Article
  • Censoring User Comments in a Guestbook Scenario

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article