tags:

views:

66

answers:

4

I need to the the bin path of the executing assembly. How do you get it? I have a folder Plugins in the Bin/Debug and I need to get the location

+3  A: 

Here is how you get the execution path of the application:

path = System.IO.Path.GetDirectoryName( 
      System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

http://msdn.microsoft.com/en-us/library/aa457089.aspx

Kevin
Hi,thanks for your prompt reply. Why is it that if I hardcode the path it finds it and if I do the following code it doesnt .The only difference I can see is the "\\" .Am I missing something? var binpath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); var fullpath = Path.Combine(binpath, folderName); if (!Directory.Exists(fullpath)) return;
A: 

You could do this

    Assembly ass = Assembly.GetExecutingAssembly();
    string path = System.IO.Path.GetDirectoryName(ass.Location);
TooFat
HiGot a problem with UNC Path any suggestions
A: 
var assemblyPath = Assembly.GetExecutingAssembly().CodeBase;
James Curran
+1  A: 
Path.GetDirectoryName(Application.ExecutablePath)

eg. value:

C:\Projects\ConsoleApplication1\bin\Debug
Turek