Re: How should control images should be handled?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: John Saunders (johnwsaundersiii)
Date: 11/03/04


Date: Wed, 3 Nov 2004 07:30:20 -0500


"~~~ .NET Ed ~~~" <tiredofspam@abolishspam.now> wrote in message
news:Os%23R843vEHA.2016@TK2MSFTNGP15.phx.gbl...
> This is something that has been nagging me over and over again and I think
> there must be a better solution out there.
>
> Some times (usually?) user controls and custom web controls need images
> such
> as icons and other decorations in the form of images. The problem is...
> how
> do you handle that in a way that everything is self-contained or at least
> free form file system dependencies?
>
> For example, the control needs a few icons and some background image for
> part of the control. Is there a way to make it self-contained in the
> Assembly? and if so, how can I extract/handle such image for use in an
> HTML
> tag such as <img src= "icon.png"> ?

You don't.

When the browser sees that <img> tag, it issues an HTTP request for
icon.png. The web server will either find that file and return it, or will
return an error. Having the file sitting around in your assembly just won't
do it, because the web server isn't going to go looking in your assembly.

Of course, the alternative would be to get the web browser to look in your
assembly. :-)

You can do that by writing a custom HttpHandler and configuring the web site
to call it whenever there is a request for a particular resource. For
instance, you could put "icon.png" for a control called "MyControl" which
resides in a web application called "/app" in "/app/icon.png.MyControl". If
you configure the HttpHandler to process all requests for *.MyControl, then
it will be able to look in the assembly which MyControl is in for the
appropriate resources.

> I typically put all my images in the img directory at the root of my web
> host account. Now, in a production system this would simply translate to
> http://www.mydomain.com/img/icon.png. But then on my development machine
> my
> root directory is actually a virtual directory that is accessed as
> http://localhost/mydomain/img/icon.png. That means that in production my
> root is actually the domain root, while in the development system the root
> is actually an application directory, a subdirectory of the IIS root.

Try using "~/img/icon.png" in any server-side control. In particular:

<img runat="server" src="~/img/icon.png">

That will look in the appropriate place depending on where your application
is deployed.

John Saunders



Relevant Pages

  • How should control images should be handled?
    ... Some times user controls and custom web controls need images such ... part of the control. ... I typically put all my images in the img directory at the root of my web ... But then on my development machine my ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: using ~ (virtual path) with images
    ... > I made a header control in asp.net and it references images in the ... > folder in the virtural path's root folder... ...
    (microsoft.public.dotnet.framework.aspnet)
  • ANN: JfControls Standard (New version: 06.04.01)
    ... now with support for Delphi 2005 Update 2 ... JfControls is much than just a set of components here and there. ... By means of this program you could see the images contained in a package ... to control the destruction of windows, embedded forms, ... ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Conditional Formatting for Image box on Continuous Forms - Again
    ... Regarding the Flex Grid control, I got it by installing Visual Studio ... different records in a continuous form. ... Then you can just copy and paste your images into the relevant fields ... Advice that I've ...
    (microsoft.public.access.forms)
  • ANN: JfControls Standard (04.12.18)
    ... JfControls is much than just a set of components here and there. ... By means of this program you could see the images contained in a package ... Resizable windows with skin. ... to control the destruction of windows, embedded forms, ... ...
    (borland.public.delphi.thirdpartytools.general)