path problem

  • Thread starter faisal jawaid via .NET 247
  • 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.
 
D

Drebin

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;

}
 
D

Drebin

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;

}
 
M

Matt Berther

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top