473,412 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Load a resource from any namespace in project?

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
1 2175
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nils Erik Asmundvaag | last post by:
Hello I hope someone is able to help me with this frustrating problem. I have a C# web project in Visual Studio .NET 2003. I want to support Swedish and Norwegian texts and have put the texts...
2
by: Cindy Liu | last post by:
Hi, If my xml resource file is directly under my project file, I have no problem to load that xml file via Assembly.GetManifestResourceStream. However, after I create a folder under the project...
5
by: Drew | last post by:
Assembly asm = Assembly.GetExecutingAssembly(); me = new Bitmap(asm.GetManifestResourceStream("me.gif")); I have used this before without any problem, but now I get: An unhandled exception...
10
by: mphanke | last post by:
Hi, I have an application that works fine when compiled as an executable. But it is designed to be a plugin also at the same time, by compiling it as a dll. I have a problem with resources...
3
by: Kelmen Wong | last post by:
I'm having a real hard-time to work out the hell of the statelite assembly. 1) At start, the official MSDN stated to use: .... new ResourceManager(strBaseName,...
4
by: Jason Pettys | last post by:
In an ASP.NET project I am setting the content type of my .ascx and ..aspx files to Embedded Resource for a separate reason. When I do this they get embedded as "RootNamespace.Filename" but I...
1
by: coz | last post by:
Someone please help! I cannot for the life of me get a web resource in asp.net 2.0 to return any content. I know I have correctly embedded my resources (because I can manually get the resources...
1
by: Steve Richter | last post by:
I am embedding an xml file in my class library assembly. In solution explorer I right click a folder, add , new item, xml file. then on the xml file I right click, properties, build action =...
10
by: Alain R. | last post by:
Hi, I have some problem to retrieve an image from my application. Here is my code : Stream imgStream = null; Assembly a = Assembly.GetExecutingAssembly(); imgStream =...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.