Let me ask how to get the file path of the dll within a function inside the dll in C# 4.0? Please let me know how only using C# ,but not using win API directly.
Thank you in advance.
Let me ask how to get the file path of the dll within a function inside the dll in C# 4.0? Please let me know how only using C# ,but not using win API directly.
Thank you in advance.
Have you tried this?
string path = System.Reflection.Assembly.GetExecutingAssembly().Location
string currentAssemblyDirectoryName =
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Beware that Assembly.Location property returns the location of the assembly file after it is shadow-copied. In addition , if it is dynamically loaded using Load method, it returns empty string .
If you are interested in retrieving the location of the assembly before it is shadow-copied or loaded, use Assembly.CodeBase property instead. Please note that, it is the location specified originally while stating the AssemblyName.
Reference here
You could use:
Assembly.GetExecutingAssembly().Location
Although if you are inside an ASP.NET application, due to shadow copying, this is probably not the location that you are looking for.