private string  GetPath(string strPath)
{   string tempPath = str ;
  string ResultPath = "" ;
  while( tempPath.IndexOf(@"\") != -1)
  {
       ResultPath += tempPath.Substring(0,tempPath.IndexOf(@"\")+1) ;
       tempPath = tempPath.Substring(tempPath.IndexOf(@"\")+1,tempPath.Length -       tempPath.IndexOf(@"\")-1) ;      }
   return ResultPath ;
}

解决方案 »

  1.   

    你可以在"工具"->"自定义工具箱"中添加一个.net方面的dll文件上去,具体是哪一个我也记不清了,我下去帮你看看。它里面有一个就是专门的目录控件
      

  2.   

    sorry
    private string  GetPath(string strPath)
    {   string tempPath = strPath; //写错了 :p
      string ResultPath = "" ;
      while( tempPath.IndexOf(@"\") != -1)
      {
           ResultPath += tempPath.Substring(0,tempPath.IndexOf(@"\")+1) ;
           tempPath = tempPath.Substring(tempPath.IndexOf(@"\")+1,tempPath.Length -  tempPath.IndexOf(@"\")-1) ;      }
       return ResultPath ;
    }
      

  3.   

    》在c#中如何获得指定文件的目录,如何获得指定目录的目录?
    如果我没有理解错误的话你不是想搜索文件吧?如果只是想获得指定文件的目录,C# 提供了完全明晰的支持,你可以:string myFile = @"C:\windows\1.gif";
    FileInfo fObj = new FileInfo(myFile);MessageBox.Show("目录位于:" + fObj.DirectoryName);string myDir = @"C:\windows\Media";
    DirectoryInfo dObj = new DirectoryInfo(myDir);MessageBox.Show("上级目录:" + dObj.Parent.FullName);
    MessageBox.Show("根目录:" + dObj.Root.Name);