ASP 101 - Active Server Pages 101 weblog.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
	Sub Page_Load(sender As Object, e As EventArgs)
		' If this is first run
		If Not Page.IsPostBack Then
			txtHeadline.Text = "ASP 101"
			txtURL.Text      = ""
		End If
		pnlEntryAdded.Visible = False
	End Sub
	Sub btnAdd_OnClick(sender As Object, e As EventArgs)
		Dim strHeadline As String
		Dim strURL      As String
		Dim strNewEntry As String
		' Retrieve our form values	
		strHeadline = txtHeadline.Text
		strURL      = txtURL.Text
		If strHeadline <> "" And strURL <> "" Then
			' Formatting is completely up to you... 
			strNewEntry = "<tr><td><a href=""" & strURL & """>" _
				& "<font size=""-1"" color=""#0000FF"">" _
				& Server.HTMLEncode(strHeadline) _
				& "</font></a></td></tr>"
			Call AddNewEntryToFile(strNewEntry, "weblog.txt")
			' Page doesn't update immediately because the text file
			' gets included before the script runsso show a message
			' to that effect.
			lblEntryAdded.Text    = strHeadline
			pnlEntryAdded.Visible = True
		End If
	End Sub
	Sub AddNewEntryToFile(strNewEntry As String, strVirtualFileName As String)
		Dim strFileContents As String
		' Get existing file contents
		strFileContents = ReadTextFromFile(strVirtualFileName)
		' Pull oldest entry off the bottom
		' Assumes there is one vbCrLf at the end of each line and NO EXTRAS AT THE END OF THE FILE!!!
		strFileContents = Mid(strFileContents, 1, InStrRev(strFileContents, vbCrLf, (Len(strFileContents) - 2)))
		' Add new entry to the top
		strFileContents = strNewEntry & vbCrLf & strFileContents
		' Write full text including new entry back to file
		OverwriteFileWithText(strVirtualFileName, strFileContents)
	End Sub
	Function ReadTextFromFile(strVirtualFileName As String) As String
		' Declare the objects we'll need
		Dim objFile         As File
		Dim objStreamReader As StreamReader
		Dim strFileContents As String
		' Get a handle on the file to read from
		' and connect it to the StreamReader object
		objStreamReader = objFile.OpenText(Server.MapPath(strVirtualFileName))
		' Read the whole file
		strFileContents = objStreamReader.ReadToEnd()
		' Close the StreamReader object
		' Set the return value of our function
		ReadTextFromFile = strFileContents
	End Function
	Sub OverwriteFileWithText(strVirtualFileName As String, strFileContents As String)
		' Declare the objects we'll need
		Dim objFile         As File
		Dim objStreamWriter As StreamWriter
		' Get a handle on the file to write to
		' and connect it to the StreamWriter object
		objStreamWriter = objFile.CreateText(Server.MapPath(strVirtualFileName))
		' Write text
		' Flush to disk and close file
	End Sub
<title>ASP.NET Web Log Sample</title>
<!-- This would almost certainly be in a separate file, but for
simplicity I'm including both the reading and writing portions
of the log in the same place. -->
<p><strong>Current Web Log Contents:</strong></p>
<table border="1" cellpadding="3" cellspacing="0" width="200">
		<td bgcolor="#BCBC96">
			<strong>Cool Stuff!!!</strong>
	<!-- #include file="weblog.txt" -->
<br />
<br />
<asp:Panel id="pnlEntryAdded" runat="server">
	"<asp:Label id="lblEntryAdded" runat="server" />" added to weblog.txt.
	<a href="weblog.aspx">View updated page.</a>
<form runat="server">
<p><strong>Add New Entry:</strong></p>
		<td><asp:TextBox id="txtHeadline" runat="server" /></td>
		<td><asp:TextBox id="txtUrl" runat="server" /></td>
		<asp:Button id="btnAdd" runat="server"
			Text    = "Add Entry"
			OnClick = "btnAdd_OnClick"
<hr />
Click <a href="">here</a>
to read about and download the source code.