How do I get Bin Path?

C#.Net

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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

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

MSDN has a full reference on how to determine the Executing Application's Path.

Note that the value in path will be in the form of file:\c:\path\to\bin\folder, so before using the path you may need to strip the file:\ off the front. E.g.:

path = path.Substring(6);

Solution 2 - C#

You could do this

    Assembly asm = Assembly.GetExecutingAssembly();
    string path = System.IO.Path.GetDirectoryName(asm.Location);

Solution 3 - C#

This is what I used to accomplish to this:

System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, System.AppDomain.CurrentDomain.RelativeSearchPath ?? "");

Solution 4 - C#

var assemblyPath = Assembly.GetExecutingAssembly().CodeBase;

Solution 5 - C#

Path.GetDirectoryName(Application.ExecutablePath)

eg. value:

C:\Projects\ConsoleApplication1\bin\Debug

Solution 6 - C#

var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)?.Replace("file:\\", "");

Solution 7 - C#

Application.StartupPath

This is how you can access the bin / debug path

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser9969View Question on Stackoverflow
Solution 1 - C#kemiller2002View Answer on Stackoverflow
Solution 2 - C#etoisarobotView Answer on Stackoverflow
Solution 3 - C#ThorgeirView Answer on Stackoverflow
Solution 4 - C#James CurranView Answer on Stackoverflow
Solution 5 - C#Wojtek TurowiczView Answer on Stackoverflow
Solution 6 - C#StealthKKView Answer on Stackoverflow
Solution 7 - C#rasityilmazView Answer on Stackoverflow