C#中如何获取路径字符串的上一级路径?

来源:百度知道 编辑:UC知道 时间:2024/04/28 23:43:21
如路径字符串“C:\ABC\Temp\DC\”
我现在想取得“C:\ABC\”
如何用C#获取,好像有C#函数可做到,不太记得了

自已可以编写函数按“\”进行截取
public string getName(string path)
{
return path.substring(path.lastindexof("\"),path.length- path.lastindexof('\')-1);
}

"..\\"
退两级就用"..\\..\\"

MessageBox.Show(System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(@"C:\ABC\Temp\DC\"))));

split()