How do I get the path of the current assembly? I need to get data from some paths relative to the location of hte current assembly (.dll).
I thought someone told me to use the reflection namespace but I can't find anything in there.
How do I get the path of the current assembly? I need to get data from some paths relative to the location of hte current assembly (.dll).
I thought someone told me to use the reflection namespace but I can't find anything in there.
You can use:
Some suggestions in the comments are to pass that through
System.Uri.UnescapeDataString
(from vvnurmi) to ensure that any percent-encoding is handled, and to usePath.GetFullpath
(from TrueWill) to ensure that the path is in standard Windows form (rather than having slashes instead of backslashes). Here's an example of what you get at each stage:Output if we're running
C:\Temp\Temp App\bin\Debug\TempApp.EXE
:I prefer
EscapedCodeBase covers the scenario where your local path might have an invalid URI char in it (see https://stackoverflow.com/a/21056435/852208)
LocalPath includes the full path for both local paths and unc paths, where AbsolutePath trims off "\\server"
Just to make it clear:
System.Reflection.
Assembly
.GetExecutingAssembly()
.Location