[dba-VB] C# get project directory

jwcolby jwcolby at colbyconsulting.com
Mon Sep 21 10:02:27 CDT 2009


Gustav,

I was hoping to find a property of some object that told me the solution base directory.  It SEEMS 
SO LOGICAL.  Sigh.

I have every intention of creating a directory of my own to hold some files that this thing will 
create.  I just want that directory to be portable (change with the location of the solution) and as 
close to the base solution path as possible.  If you are using Explorer to go find the files it is 
annoying to be six levels down from the solution base.

Thanks for this solution.  It definitely should work.

John W. Colby
www.ColbyConsulting.com


Gustav Brock wrote:
> 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,
> 



More information about the dba-VB mailing list