[dba-VB] C# get project directory

Gustav Brock Gustav at cactus.dk
Mon Sep 21 09:48:38 CDT 2009


Hi John

Another method with strings only is a bit long winded:

string folder = Directory.GetParent(Directory.GetParent(Path.GetDirectoryName(Application.ExecutablePath)).FullName).FullName;

or - applying a bit of the good old DOS syntax:

string folder = Directory.GetParent(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "..")).FullName;

For your purpose I think too, that a parent directory should not be used, rather a subdirectory, like:

string dataPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Data");

/gustav


>>> jwcolby at colbyconsulting.com 21-09-2009 15:42:13 >>>
I want to set up a directory to store files directly under the project directory.  I can get the exe 
directory using Application.ExecutablePath but that is clear down in the bin directory etc.

I want THIS path:

E:\C# Projects\Grade Calculator	<<<<<

I have Googled till I am blue in the face and all I end up with is (where the exe is):

D:\C# Project\Grade Calculator\Grade Calculator\bin\Debug

Any help appreciated.

Thanks,

-- 
John W. Colby
www.ColbyConsulting.com 






More information about the dba-VB mailing list