Yeah, that is the preferred way. Original poster however asked how to do
that all with a server control, so I thought he had considered HtttpHandler
option already.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
The way I deal with this is to have the Image resources for my custom
controls embedded in the DLL (of the Class Library, not a part of the site).
I have created an HttpHandler to handle the requests and configured the IIS
Application to send requests for .ERES to my handler. I can then use a path
to the DLL specially formatted URL to access any image resource. This works
extremely well for packaging up you images (or any content including .js
files) for distribution but has a small issue with design visibility that I
am currently working on.
I have attached all the code for the handler to this message and the
following code is how you would use it:
string urlString =
HttpHandlers.HttpEmbeddedResourceHandler.GetResourceURL(this.Context,
this.GetType().Assembly, "Controls/Images/UpdateButton.gif");
The UpdateButton.gif file in the project is in the Controls/Images directory
and it's "Build Action" is set to Embedded Resource.
Hope this all helps!
Fred
----- Following is the comment on the attached source file...
This HttpHandler is used to extract embedded resources for controls. There
are a couple of configuration
settings that must be done before an application can actually use the
controls (to use the embedded
resources).
1) The Web Application must be configured (using IIS console) to have an
additional mapping under the
configuration tab. Add a new mapping that has the "aspnet_isapi.dll" as
the executable and .eres as the
file extension. Make sure to unselect the "Check that file exists"
checkbox as these files do not actually
exist.
2) Add the following mapping to the web.config file under <system.web>
<httpHandlers>
<add verb="*" path="*.eres"
type="SierraSystems.Web.HttpHandlers.HttpEmbeddedResourceHandler,
SierraSystems.Web"
validate="true" />
</httpHandlers>
Controls can now create a URL to the embedded resources, the format of the
URL is:
http://webserver/appname/[AssemblyName]/[ResourcePath].eres
EG:
http://webserver/app/SierraSystems.Web/Controls/Images/AddButton.gif.eres