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      = "http://www.asp101.com/"
		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
		objStreamReader.Close()
		' 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
		objStreamWriter.Write(strFileContents)
		' Flush to disk and close file
		objStreamWriter.Flush
		objStreamWriter.Close
	End Sub
</script>
<html>
<head>
<title>ASP.NET Web Log Sample</title>
</head>
<body>
<!-- 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">
	<tr>
		<td bgcolor="#BCBC96">
			<strong>Cool Stuff!!!</strong>
		</td>
	</tr>
	<!-- #include file="weblog.txt" -->
</table>
<br />
<br />
<asp:Panel id="pnlEntryAdded" runat="server">
	<p>
	"<asp:Label id="lblEntryAdded" runat="server" />" added to weblog.txt.
	</p>
	<p>
	<a href="weblog.aspx">View updated page.</a>
	</p>
</asp:Panel>
<form runat="server">
<p><strong>Add New Entry:</strong></p>
<table>
	<tr>
		<td><strong>Headline:</strong></td>
		<td><asp:TextBox id="txtHeadline" runat="server" /></td>
	</tr>
	<tr>
		<td><strong>URL:</strong></td>
		<td><asp:TextBox id="txtUrl" runat="server" /></td>
	</tr>
	<tr>
		<td></td>
		<td>
		<asp:Button id="btnAdd" runat="server"
			Text    = "Add Entry"
			OnClick = "btnAdd_OnClick"
		/>
		</td>
	</tr>
</table>
</form>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/weblog_aspx.asp">here</a>
to read about and download the source code.
</p>
</body>
</html>