ASP 101 - Active Server Pages 101 source.aspx
<%@ Page Language="VB" EnableViewState="False" %>
<%@ Import Namespace="System.IO" %>
<script Language="VB" Option="Explicit" runat="server">
	Sub Page_Load(sender as Object, e as EventArgs)
		Dim strFileName As String
		strFileName = Request.QueryString("file")
		' Add this so that people see this file's source code if they
		' don't pass in any parameters.
		If strFileName = "" Then strFileName = "source.aspx"
		If InStr(1, strFileName, "\", 1) <> 0  Then strFileName = ""
		If InStr(1, strFileName, "/", 1) <> 0  Then strFileName = ""
		If InStr(1, strFileName, "..", 1) <> 0 Then strFileName = ""
		lblFileName.Text = strFileName
		lblSource.Text = Server.HTMLEncode(GetTextFromFile(Server.MapPath(strFileName)))
	End Sub
	Function GetTextFromFile(strFileName 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(strFileName)
			' Read the whole file
			strFileContents = objStreamReader.ReadToEnd()
			' Close the StreamReader object
		Catch ex As Exception
			strFileContents = "Error: File Not Found!"
		End Try
		' Set the return value of our function
		GetTextFromFile = strFileContents
		' Alternate debugging line
		'GetTextFromFile = "This is NOT text read from the file!"
	End Function
 <title>ASP.NET Source Code Viewer Sample Code</title>
<a href="" target="_top"><img src="/img/asp_asp101_logo.gif" width="178" height="39" border="0" alt="ASP 101 - Active Server Pages 101" /></a>
<strong><asp:Literal id="lblFileName" runat="server" /></strong>
<hr />
<asp:Literal id="lblSource" runat="server" />
<hr />
Click <a href="">here</a>
to read about and download the source code.