using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
return;
TreeNode root = new TreeNode();
DirectoryInfo rootDir = new DirectoryInfo(Server.MapPath("~/"));
AppendChild(rootDir, root);
TreeView1.Nodes.Add(root);
}
protected void AppendChild(DirectoryInfo dir, TreeNode node)
{
DirectoryInfo[] dirs = dir.GetDirectories();
if (dirs.Length > 0)
{
for (int i = 0; i < dirs.Length; i++)
{
TreeNode sub = new TreeNode(dirs[i].Name);
AppendChild(dirs[i], sub);
node.ChildNodes.Add(sub);
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
Response.Write( "当前的物理路径是 : " + Server.MapPath("~/" + TreeView1.SelectedNode.Text));
}
}