Embedded resource question

T

Tomer

Hi,

I've a gif in my project inside one of its directories (for example: Graphics\Icons), its is compiled as embedded resource.

I can't get the gif's stream when calling the method:
Assembly.GetExecutingAssembly().GetManifestResourceStream("GUI.Battery1.gif");
Where GUI is the assembly name, and Battery1.gif is the image name.

This line works fine when the image is in the root of the project.

How can I make it work from directories?



Tomer.
 
S

Sergey Bogdanov

Assuming that your image is placed into directory "Graphics\Icons" to
retrieve this image you should write something like this:

Assembly.GetExecutingAssembly().GetManifestResourceStream("GUI.Graphics.Icons.Battery1.gif");

Since you have to explicitly set the full path to the image in you assembly.
 
S

Sergey Bogdanov

A namespace can't contain whitespaces that's why you can't embed your
image into the directory with a space like "Status bar" but you can
rename it like "Status_Bar", "StatusBar" ...
Will it work with directories with embedded spaces, like "Status bar\Icons"?

Tomer.
 
T

Tomer

Thanks a bunch!!!

Tomer.



Sergey Bogdanov said:
A namespace can't contain whitespaces that's why you can't embed your
image into the directory with a space like "Status bar" but you can
rename it like "Status_Bar", "StatusBar" ...
 
J

John Kendrick

Actually you can place resources in folders with spaces like "Status bar".
When referencing this is code you substitute the space with an underscore
like "Status_bar" and Visual Studio does the rest.

Sergey Bogdanov said:
A namespace can't contain whitespaces that's why you can't embed your
image into the directory with a space like "Status bar" but you can
rename it like "Status_Bar", "StatusBar" ...
 

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