I quickly through this sample together because someone in the newsgroups wanted a way to create a filesystem view through the ASP.Net TreeView control. Note: I'm not touching this with icons or any other niceness, that's an exercise left to the reader:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<script runat="server" language="C#">
protected void Page_Load(object sender, EventArgs e)
{
System.IO.DirectoryInfo di =
new System.IO.DirectoryInfo(@"c:\mydirectory\mydirectoryschild\");
TreeNode root = new TreeNode(di.Name);
this.TreeView1.Nodes.Add(root);
HydrateTree(di, root);
}
private void HydrateTree(System.IO.DirectoryInfo dir, TreeNode parent)
{
foreach (System.IO.FileInfo file in dir.GetFiles())
{
parent.ChildNodes.Add(new TreeNode(file.Name));
}
foreach (System.IO.DirectoryInfo di in dir.GetDirectories())
{
TreeNode child = new TreeNode(di.Name);
parent.ChildNodes.Add(child);
HydrateTree(di, child);
}
return;
}
</script>
<asp:TreeView ID="TreeView1" runat="server">
</asp:TreeView>
This is what it looks like on my machine:

Recommended reading:


