How do I find the parent directory in C#?

string parent = System.IO.Directory.GetParent(str_directory).FullName;

See BOL


If you append ..\.. to your existing path, the operating system will correctly browse the grand-parent folder.

That should do the job:

System.IO.Path.Combine("C:\\Users\\Masoud\\Documents\\Visual Studio 2008\\Projects\\MyProj\\MyProj\\bin\\Debug", @"..\..");

If you browse that path, you will browse the grand-parent directory.


You can use System.IO.Directory.GetParent() to retrieve the parent directory of a given directory.