By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,967 Members | 1,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,967 IT Pros & Developers. It's quick & easy.

Load a resource from any namespace in project?

P: n/a
How can I load a resource from any namespace in my project?

I have all my icons located under the following namespace:

..\resources\images\

For example, I can not figure out how to load them from the following
namespace:

..\ui\views\navcontroller\

Thanks in advance for any tips or suggestions,

-Ed
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Ed,

It depends what kind of resource you want to load. For example if you load
bitmap it constructor has an ovreload that accepts Type object. This type
used only to get the name of the namespace. You can privide any type it
doesn't have to be *this.GetType()*. If you have a type decalred in the same
namespace as the resource or the namespace of the type forms some sufix of
the namspace of the resources you can use it.

For example let say we want to load a bitmap that is located in
FooNamespace.Images.pic.jpg
and you have a class in the FooNamspace you can load the bitmap as

new Bitmap(typeof(Foo), "Images.pic.jpg");
the bitmap constructor will take 'FooNamspace' from the Foo's type object.

If for example you have any kind of resource or there is no class in this
namespace
you can get reference to the Assembly that has that resource and get the
resource as a stream

Stream s =
assem.GetManifestResourceGetManifestResourceStream (FooNamespace.Images.pic.jpg);

And then load the resource from the stream.

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Ed Sutton" <S_*************@nomadics.com> wrote in message
news:ei*************@TK2MSFTNGP14.phx.gbl...
How can I load a resource from any namespace in my project?

I have all my icons located under the following namespace:

.\resources\images\

For example, I can not figure out how to load them from the following
namespace:

.\ui\views\navcontroller\

Thanks in advance for any tips or suggestions,

-Ed

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.