Hi Chris,
IF you are dealing with an ASP.NET app then it's a different history, as is
the aspnet_wp.exe the one that is executing and he is the one that load your
dlls ( that are locate in the /bin directory ) , what you can get is the
physical directory of your application, you do this by using
HttpServerUtility.MapPath this is the only way I know to get the location,
after that you know that the dll is located under the /bin directory.
now the tricky part is that you want ot know that from inside the dll ,
usually HttpServerUtility is only accesible from the asp.net application, I
would advice you agains including code to use HttpServerUtility.MapPath
inside the dll, cause if other day you want to use it from a windows app
then you are going to get errors.
My suggested solution:
declare a static public property like:
public static string ConfigFileLocation="";
declare a flag as :
private bool isLoadedConfig = false;
then in the method or methods that you need info from this file you check
first for this flag:
if ( ! isLoadedConfig )
LoadConfig();
this method check to see if ConfigFileLocation is emtpy if so then you use
System.Reflection.Assembly.GetExecutingAssembly.Location , otherwise you use
the string provided in the ConfigFileLocation variable.
Of course you would have to check if the file exist , otherwise you throw
an exception
Something like this:
void LoadConfig()
{
string path = (ConfigFileLocation=="") ?
System.Reflection.Assembly.GetExecutingAssembly.Location :
ConfigFileLocation;
if ( ! File.Exist( path) )
throw new Exception ("File Not Found");
}
Anyway this is a possible solution, you have to check the code above, cause
I just write it down in OE
Hope this help,