Add an image to a dll

Hey all,

I have a dll component which will be used by a large number of webprojects.
This dll component contains some WebControls that will be rendered to the page, including ImageButtons.

Now, what I want is that I do not have to copy a directory containing the images for the ImageButtons to every webproject that will use my dll component.
I know that you can embed images as a resource in your project, but as far as I can tell, that only goes for Btimap objects which you can load using a stream, not for ImageButtons that will look for a path.

So in short, I want to be able to add a reference to the dll component from a webproject, and that the images for my imagebuttons will still be found.

How do I do this? Is this possible?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Would extracting images from an assembly, create a file, and then mapping the ImageButton's ImageURL to the temporary file be feasible?

Razzie_Author Commented:
Do you mean embedding the images as a resource and extracting / saving them at run-time? If you do, then I'm afraid not, because that would mean a performance hit, and I'm not willing to sacrifice performance for this (which is only a nuisance, but no big deal).
Bob LearnedCommented:
Ok, then, how about a one-time performance hit, by not using temporary files, but embed all the images within a resource DLL, and then detect if the image files exist, and if not, then create them by extracting from the DLL and saving to disk, otherwise, go on with the page?

OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Bob is right.  Creating the files at runtime would be the only way around it.  The HTML code ASP.NET generates will look for a static image file.  No ifs, ands or buts about it.  There has to be an image file for the ImageButton to link to.

I think the idea is nice, but I don't see that it would be difficult to copy a folder of images to whatever servers need them.  You won't be saving any file size and you definitely won't increase your performance.  It seems like compiling the images into an assembly and writing the code to extract them would take more time than it would have to just copy the whole image folder in the first place.
Bob LearnedCommented:
Plus, the overhead of managing images, when you add/delete them.

Maybe I shouldn't say it's impossible, but just... unreasonable.  I suppose there is probably a way to catch requests from IIS, execute some code and stream out an image file in the Http response... But I have no idea how.
Bob LearnedCommented:
Well, you could add the image stuff to the Output stream, with a little bit of magic, of which I don't have.

Bob LearnedCommented:
Proof of concept:


What about something like the following; I haven't tried it, but it seems like it should work:

Assembly assembly = Assembly.Load(assemblyName);
Image image = Image.FromStream(assembly.GetManifestResourceStream(imageName));
image.Save(Response.OutputStream, ImageFormat.Gif);

Stick that in its own ASPX page (like image.aspx) and then pass in a query string with imageName.  Then reference it like so:

<img src="image.aspx?image=SomeImage.gif" />

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
haha, I love how I just went from basically saying its not possible to having some code to use.
Bob LearnedCommented:
Transporting and Displaying Images using DIME and HTTP Handlers:

Bob LearnedCommented:
Displaying multiple dynamic images in a WebForm:

Hmm... I hadn't thought about Http handlers.  I suppose you could stick that code in an ASHX file instead of an ASPX file and reduce some overhead.
Razzie_Author Commented:
Sorry for the late response, but wasn't actively working on this for the last week.

I found this article myself too which did have some good information also.

Thanks for all the input.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.