Click here to Skip to main content
14,302,372 members
Rate this:
Please Sign up or sign in to vote.
See more:
How can I find the root directory of my c# console application?

I've tried a few suggestions so far but all return the location of my executable like the following:
"C:\AppName\Source\Client.AppName\bin\Release"

However I want to return the following:
"C:\AppName\Source\Client.AppName"

Any idea how I can get this?

Thanks.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 2

C:\AppName\Source\Client.AppName\bin\Release

that is the root directory. the root being where your application runs from. Why do you need to get up to where the project is from within your application?

If it's for resources etc. In VS, select them, look at the properties and set the Build Action to Content and Copy If Newer as the "Copy To Output Directory" option.
   
Comments
Kunal Chowdhury «IN» 22-Jul-10 14:19pm
   
Reason for my vote of 5
This has more clear answer.
Rate this:
Please Sign up or sign in to vote.

Solution 1

I think you will have to remove the "\bin\Release" substring yourself as the system cannot make that determination for you. For example if you move your executable to "C:\Program Files\yourname\test" there is no link between the exe and the source code.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100