ASP 101 - Active Server Pages 101 dir_list_filtered.aspx
<%@ Page Language="VB" EnableViewState="False" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
	Sub Page_Load(sender as Object, e as EventArgs)
		Dim strPath   As String = "filtered/"
		Dim strQuery  As String
		Dim myDirInfo As DirectoryInfo
		strQuery = txtQuery.Text
		If strQuery = "" Then strQuery = CStr(Request.QueryString("query"))
		txtQuery.Text = strQuery
		lblPath.Text = strPath
		myDirInfo = New DirectoryInfo(Server.MapPath(strPath))
		'Response.Write("*" & strQuery & "*")
		dgFileList.DataSource = myDirInfo.GetFiles("*" & strQuery & "*")
		dgFileList.DataBind()
	End Sub
</script>
<html>
<head>
<title>ASP.NET Directory List (Filtered) Sample</title>
</head>
<body>
<form runat="server">
Find files whose names contain:
<asp:TextBox id="txtQuery" runat="server" /><br />
<input type="submit" value="Find Files" />
</form>
<p>
Some sample queries:
<a href="<%= Request.ServerVariables("URL") %>?query=ary">ary</a>,
<a href="<%= Request.ServerVariables("URL") %>?query=ber">ber</a>,
<a href="<%= Request.ServerVariables("URL") %>?query=0">0</a>,
<a href="<%= Request.ServerVariables("URL") %>?query=1">1</a>,
<a href="<%= Request.ServerVariables("URL") %>">show all files</a>.
</p>
<p>
Contents of <strong><asp:Literal id="lblPath" runat="server" /></strong> that match your query:
</p>
<asp:DataGrid id="dgFileList" runat="server"
	Border                = 5
	BorderColor           = "green"
	CellSpacing           = 0
	CellPadding           = 2
    HeaderStyle-BackColor = "#006600"
    HeaderStyle-ForeColor = "#FFFFFF"
    HeaderStyle-Font-Bold = "True"
    ItemStyle-BackColor   = "#CCFFCC"
    AutoGenerateColumns   = "False"
    >
	<Columns>
		<asp:HyperLinkColumn DataNavigateUrlField="Name" DataNavigateUrlFormatString="filtered/{0}" DataTextField="Name" HeaderText="File Name:" />
		<asp:BoundColumn DataField="Length" HeaderText="File Size:" ItemStyle-HorizontalAlign="Right" />
		<asp:BoundColumn DataField="LastWriteTime" HeaderText="Date Created:" />
	</Columns>
</asp:DataGrid>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/dir_list_filtered_aspx.asp">here</a> to read about and download the source code.
</p>
</body>
</html>