path problem

  • Thread starter Thread starter faisal jawaid via .NET 247
  • Start date Start date
F

faisal jawaid via .NET 247

i have two projects/
project a, project b

project a is refferencing project b (class library).
i want to get the directory path of the project b (class library)
as i can get the project a path from

System.reflection.Assembly.GetExecutingAssembly().CodeBase
and etc.
but i need my class library directory path at runtime.
 
I assume you mean project B is in a different directory? If so, you could do
something like this (code not tested):

System.Reflection.Module[] arrModules =
System.Reflection.Assembly.GetEntryAssembly().GetLoadedModules();

for (int n=0; n<arrModules.Length ; n++)

{

if ( arrModules[n].Assembly.FullName == "Myassembly" )

return arrModules[n].Assembly.CodeBase;

}
 
Always overthinking the problem.. disregard that last post, here is working
code that you would call from ClassA:

MyNameSpace.ClassB objClassB = new MyNameSpace.ClassB();

System.Reflection.Assembly objAss =
System.Reflection.Assembly.GetAssembly(objClassB.GetType());

MessageBox.Show(objAss.CodeBase);


HTH


Drebin said:
I assume you mean project B is in a different directory? If so, you could do
something like this (code not tested):

System.Reflection.Module[] arrModules =
System.Reflection.Assembly.GetEntryAssembly().GetLoadedModules();

for (int n=0; n<arrModules.Length ; n++)

{

if ( arrModules[n].Assembly.FullName == "Myassembly" )

return arrModules[n].Assembly.CodeBase;

}
 
Hello Drebin,

And saving the creation of a temp variable...

System.Reflection.Assembly objAss = System.Reflection.Assembly.GetAssembly(typeof(MyNameSpace.ClassB));
MessageBox.Show(objAss.CodeBase);

--
Matt Berther
http://www.mattberther.com
Always overthinking the problem.. disregard that last post, here is
working code that you would call from ClassA:

MyNameSpace.ClassB objClassB = new MyNameSpace.ClassB();

System.Reflection.Assembly objAss =
System.Reflection.Assembly.GetAssembly(objClassB.GetType());
MessageBox.Show(objAss.CodeBase);

HTH

Drebin said:
I assume you mean project B is in a different directory? If so, you
could
do

something like this (code not tested):

System.Reflection.Module[] arrModules =
System.Reflection.Assembly.GetEntryAssembly().GetLoadedModules();
for (int n=0; n<arrModules.Length ; n++)

{

if ( arrModules[n].Assembly.FullName == "Myassembly" )

return arrModules[n].Assembly.CodeBase;

}

i have two projects/
project a, project b
project a is refferencing project b (class library).
i want to get the directory path of the project b (class library)
as i can get the project a path from
System.reflection.Assembly.GetExecutingAssembly().CodeBase
and etc.
but i need my class library directory path at runtime.
 
Back
Top