日期:2011-10-03  浏览次数:20489 次

Asp.net IO类递归显示目录信息

.aspx.cs代码

private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   string strDirlist=Request.QueryString.Get("dir");
   DirectoryInfo thisOne=new DirectoryInfo(strDirlist);
   Response.Write("<pre>");
   ListTreeShow(thisOne,0);
   Response.Write("</pre>");
  }
  private void ListTreeShow(DirectoryInfo theDir,int nLevel){
   DirectoryInfo[] subDirectories=theDir.GetDirectories();
   for(int i=0;i<subDirectories.Length;i++){
    Response.Write(nLevel);
    Response.Write(subDirectories[i].Name+"\r\n");
    ListTreeShow(subDirectories[i],nLevel+1);
   }
      }