2011-05-10 109 views
0

如何獲取以下目錄的父目錄?訪問父目錄

string rootFolder = System.Web.HttpContext.Current.Server.MapPath(APP_PATH); 
+0

你的意思是父物理文件夾? – mohammedn 2011-05-10 10:17:43

回答

2

new DirectoryInfo(rootFolder).Parent.FullNameDirectory.GetParent(rootFolder).FullName

+0

出於某種原因,GetParent給我完全相同的文件夾 – user517406 2011-05-10 10:23:06

+0

這就是讓我想要的文件夾:string str = Directory.GetParent(rootFolder).Parent.FullName; – user517406 2011-05-10 10:26:16

+0

在這種情況下,您可以使用'new DirectoryInfo(rootFolder).Parent.FullName'來提高可讀性。 – 2011-05-10 10:28:24