0

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.

seven_swodniw
  • 881
  • 3
  • 9
  • 15

4 Answers4

3

Have you tried this?

string path = System.Reflection.Assembly.GetExecutingAssembly().Location
ABH
  • 3,391
  • 23
  • 26
2
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

Arion
  • 31,011
  • 10
  • 70
  • 88
1

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1
this.GetType().Assembly.Location;
Vano Maisuradze
  • 5,829
  • 6
  • 45
  • 73