Alex wrote:
Hi. I need some help on this.
I have a user control (a header) in my root directory, and all my pages use
that control. Then a created a folder (in my root directory) and put a new
page inside it, and that page use the same control, but this time the
control can't find it's images and resources because it is trying to find it
in the same folder instead of the root directory. Now, I know that I can
change the control image's relative paths for absolute paths, but then when
I upload my application to the real server I have to change all the paths
again. Of course I could make a copy of the control in my new folder but
then I have to copy all the images and everything too.
Is there some simple way of dealing with that?
Alex, the best approach is to use either:
(a) Absolute paths (i.e., not relative ones)
(b) The ~ character in your Web controls
For (a), what this would mean, is rather than your paths being things like:
<img src="../images/red.gif" />
-or-
<img src="img/blue.jpg" />
You'd instead use fully qualified, absolute paths, like:
<img src="/Foo/Dir2/images/blue.gif" />
The problem with this is if you have a Web application on your local
server at /Foo, but this will be moved to / when you deploy it. Then
/Foo/Dir2/images will become /Dir2/images when you deploy...
To solve for this problem, use the second approach listed. What you can
do is add ~ in your Web controls, which will cause the path to be
resolved automagically at runtime. So, if you have an Image web control
you could specify the path like:
<asp:Image ImageUrl="~/images/blue.gif" />
This only works in Web controls (not static HTML markup).
hth
--
Scott Mitchell
mi******@4guysfromrolla.com http://www.4GuysFromRolla.com
* When you think ASP.NET, think 4GuysFromRolla.com!