0

I am using a 3rd party website to launch a DLL I've written in .Net 4.0. The DLL will be uploaded onto the website alongside an SQLite database providing me results which I can then view on the website. I know that the website will place my DLL and SQLite database in the same directory, however I don't know where that directory will be. Is there a way for the DLL to recognise where it is so that it can locate the SQLite database? I've tried the following...

string path = GetType().Assembly.GetModules(false)[0].FullyQualifiedName;  

string path = typeof(YourClass).Assembly.Location;  

System.Reflection.Assembly.GetExecutingAssembly().Location; 

however all of these show the directory as 'C:\WINDOWS\system32\<library>.dll'. Is there any way to accomplish this or do I have to accept the inevitable and write my own website?

Thundter
  • 572
  • 9
  • 22
  • 1
    Is `C:\WINDOWS\system32\.dll` actually the wrong location, or is this the correct path, but you just want to remove the `.dll` part? – Kjartan Aug 16 '12 at 15:51
  • Did you also try `Assembly.CodeBase`? – Steve Guidi Aug 16 '12 at 18:12
  • 'C:\WINDOWS\system32\.dll' is the wrong path. I need the location of where the DLL is and I won't know where that location is before hand. Assembly.Codebase doesn't work either. – Thundter Aug 17 '12 at 16:01

2 Answers2

1

All the above mentioned methods you have tried will give you the physical location of your dll assembly, which is rightly reflected as this in your case:

C:\windows\system32\something.dll

On the other hand, if you want to know the physical location of the ASP.NET website that is currently referring your assembly or library, you can try one of these:

Server.MapPath(".")
Server.MapPath("~")

See this SO link for more details: Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?

Community
  • 1
  • 1
Prahlad Yeri
  • 3,210
  • 4
  • 22
  • 48
0

I may have misunderstood you (see my comment below the question), but if you just want the directory, try the following (where path is the result of one of your original attempts):

var yourDir = Path.GetDirectoryName(path)

Note: This requires you to include System.IO;.

Kjartan
  • 17,127
  • 14
  • 67
  • 84