2

Possible Duplicate:
GetEntryAssembly for web applications

There is class library which gets its executing assembly location by calling GetEntryAssembly(). However using that class library in ASP.NET web application that function returns null.

Is it possible to get location of ASP.NET application executable from class library which it calls?

GetCallingAssembly() is not suitable since the function is not called directly from web application.

Community
  • 1
  • 1
Chesnokov Yuriy
  • 1,560
  • 5
  • 19
  • 33

3 Answers3

1

Have a look at HttpRuntime.BinDirectory - "Gets the physical path to the /bin directory for the current application."

This should return the directory that all the dll's for your web application are stored in.

EDIT:

Ok, based upon your feedback, this might work:

var webApplicationType = typeof(MyWebApplicationClass);
var assemblyPathAndName = new System.Uri(webApplicationType.Assembly.CodeBase)).LocalPath;

You will need to replace 'MyWebApplicationClass' with the name of any class in the web project that you want the assembly path and name for.

Trevor Pilley
  • 15,242
  • 5
  • 40
  • 57
0

I think Server.MapPath can resolve your problem, check out this answer :- Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?

Also still if you need to find assembly path then you can use string fullPath = System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location;

check out following for more :- How do I get the path of the assembly the code is in?

Community
  • 1
  • 1
Deepesh
  • 4,626
  • 6
  • 27
  • 45
0

Try using reflection as shown below.

string path = new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath;

Hope that helps.

Thanks Milind

Milind Thakkar
  • 980
  • 2
  • 13
  • 20