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
		Try
			' 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
			objStreamReader.Close()
		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
</script>
<html>
<head>
 <title>ASP.NET Source Code Viewer Sample Code</title>
</head>
<body>
<a href="http://www.asp101.com/" 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 />
<pre>
<asp:Literal id="lblSource" runat="server" />
</pre>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/source_aspx.asp">here</a>
to read about and download the source code.
</p>
</body>
</html>