日期:2014-05-18  浏览次数:20482 次

|M| 我写了一个读取网站文件夹的事型代码,但样让文件夹按名字排呢
void   BindDir(DirectoryInfo   dir,   TreeNode   node)
        {
                DirectoryInfo[]   subdir   =   dir.GetDirectories();

                for   (Int32   i   =   0;   i   <=   subdir.Length   -   1;   i++)
                {
                        TreeNode   childnode   =   new   TreeNode();
                        childnode.Text   =   subdir[i].Name;
                        childnode.Value   =   subdir[i].FullName;
                        node.ChildNodes.Add(childnode);
                        BindDir(subdir[i],   childnode);
                }
                FileInfo[]   file   =   dir.GetFiles();
                for   (Int32   j   =   0;   j   <=   file.Length   -   1;   j++)
                {
                        TreeNode   childnode   =   new   TreeNode();
                        childnode.Text   =   file[j].Name;
                        childnode.Value   =   file[j].FullName;
                        node.ChildNodes.Add(childnode);
                }
        }  
这样得出来的会变成
2007
      02
      03
      01
而我想要的是
2007
      01
      02
      03
----------------------------------
上面代码要怎么改
谢谢

------解决方案--------------------
土方法就是把全部数据填入List里面排序一下再出来循环
------解决方案--------------------
for (Int32 j = file.Length - 1; j > =0; j--)
{
TreeNode childnode = new TreeNode();
childnode.Text = file[j].Name;
childnode.Value = file[j].FullName;
node.ChildNodes.Add(childnode);
}

就OK了
------解决方案--------------------
看错了 上页的不行 我再写
------解决方案--------------------
mark
------解决方案--------------------
这样是排序,再依次添加到树上就行了。当然也可以用List或ArrayList,只是觉得那样数据格式要转换来转换去,效率不高
TreeNode tempNode=new TreeNode();
TreeNodeCollection tnc=new TreeNodeCollection();
//tnc在此初使化 填充数据
ArrayList tempList=new ArrayList(8);
int maxPos=0;
for (int i=0;i <tnc.Count;i++)
{
for (int j=i;j <tnc.Count;j++)