How do I get Bin Path?
C#.NetC# 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