469,935 Members | 2,155 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

User control + relative path

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?
Thanks,
Alejandro Penate-Diaz.


Nov 18 '05 #1
2 2219
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!
Nov 18 '05 #2
Thanks a lot. I think that I should use server controls instead of html
images, or better, I will use skmMenu instead of mine. ;-).
thanks, Alejandro Penate-Diaz.


"Scott Mitchell [MVP]" <mi******@4guysfromrolla.com> wrote in message
news:41**************@4guysfromrolla.com...
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!

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Adie | last post: by
1 post views Thread by Dave | last post: by
1 post views Thread by Guadala Harry | last post: by
8 posts views Thread by Paul Bromley | last post: by
4 posts views Thread by =?Utf-8?B?Qkw=?= | last post: by
1 post views Thread by gnewsgroup | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.