请高手告诉小弟,用treeView控件如何绑定c盘下windows文件夹中system32文件夹中的所有内容!?
脑袋转得太慢,实在想不出来了!
希望大侠用最简单的方法告诉小弟!

解决方案 »

  1.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {
    string sPath = @"E:\Downloads";

    InitTree(sPath , this.TreeView1.Nodes);
    }
    } private void InitTree(string sPath ,TreeNodeCollection tnCollection)
    {
    if(sPath != "") sPath += @"\";
    DirectoryInfo info = new DirectoryInfo(sPath);
    DirectoryInfo[] folders = info.GetDirectories();
    foreach(DirectoryInfo dir in folders)
    {
    TreeNode tn = new TreeNode();
    tn.Text = dir.Name; tnCollection.Add(tn); InitTree(sPath + tn.Text , tnCollection[tnCollection.Count -1].Nodes);
    }
    }
      

  2.   

    读取文件夹时,需要有可读的权限.
    如果你把路径改为SYSTEM32时,可能某些文件读取不到(会出错).
      

  3.   

    感谢高手!
    可惜有个文件夹读不出来
    C:\WINDOWS\system32\config\systemprofile\
      

  4.   

    systemprofile你在这个文件的安全权限中,添加个EVERYONE的可读权限