Retrieving path of a DLL

  • Thread starter Thread starter Huy Hoang
  • Start date Start date
H

Huy Hoang

I can retrieve the path of a Windows form using the Application object.
However, if I write a class which will be compiled into a DLL, would it
be possible to retrieve the DLL path (without passing the Application
object to the class) ???
 
Yeah, I saw there was a post about the same topic, a few posts earlier.
So I deleted my starting post, but somehow you managed to reply anyway.
 
Huy,

You can do this in a many different ways, but the goal is to get reference
to the assembly and check out its Location property.

For example:
1. From code in the DLL you can do
Assembly.GetExecutingAssembly().Location

2. If Foo is a class decalred in the DLL
typeof(Foo).Assembly.Location.
or
using Assembly's static method GetAssembly()
or
using object of a type decalred in the DLL
obj.GetType().Assembly.Location

3. Using the domain AppDomain.CurrentDomain.GetAssemblies() and then finding
out your assembly and check its Location property.

I believe there are more variations on this.
 
Back
Top