Reputation: 7458
I'm trying to execute a tool-exe which is located in the same directory as main exe. For this I'm trying to obtain first the exe-name of the process using Assembly.GetExecutingAssembly and then getting the directory using IO.Path.GetDirectoryName
//1
String exePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
//2
String ncpath = System.IO.Path.GetDirectoryName(exePath);
1 returns "file:///C:/Development/RC_trunk/bin/Release/ResultConfirmation.EXE" It is an URI. Not exactly what I need but ok.
2 returns "file:\C:\Development\RC_trunk\bin\Release" Which seems to be a simple [/]+ to \ replacement.
Am I using wrong API for my problem?
P.S. IDE is VS2008
Upvotes: 2
Views: 5371
Reputation: 7830
You need to use GetExecutingAssembly.Location:
System.Reflection.Assembly.GetExecutingAssembly().Location
instead of CodeBase and then use GetDirectoryName.
Upvotes: 2
Reputation: 43264
To get the application directory, try AppDomain.CurrentDomain.BaseDirectory
.
Take a look at Best way to get application folder path for other ways of accessing the directory.
Upvotes: 2
Reputation: 7793
Use this instead for step 1)
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
Upvotes: 1