Implementing ~/...

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

I am creating some custom links via code on my Web site.

One problem I have is that I might write a link as /Images/img.gif. On my
Web site, that should work find. But on my local test computer, it is wrong
because / actual refers to the root of my developer server folder.

What I really want is ~/Images/img.gif but I'm not using a label control. Is
there a function that will take ~/Images... and change it to be the path off
my project's root dir? Perhaps the same routine called by the label
controls, etc?

Thanks for any tips.
 
Jonathan,

I am not sure why can't you use ~/Images/img.gif as it is. Asp.Net will
compile this reference to Request.ApplicationPath. Obviously, it will work
only for server-side controls, but you can turn any control to a server-side
one by just adding runat=server.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Control.ResolveUrl produces an url usable on client side. If I understand
Jonathan correctly, he needs to get right the server-side reference, that it
what Control.ResolveUrl takes to produce a client-side reference.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Then it would be Server.MapPath. As Jonathan talked about a "link" I thought
the problem was that the hyperlink is not correct client side...

Jonathan, as suggested by Eliyahu you could perhaps still have this done
automatically. We know that you don't use a label but you may want to tell
use which control exactly you are using...

----
Patrice

Eliyahu Goldin said:
Control.ResolveUrl produces an url usable on client side. If I understand
Jonathan correctly, he needs to get right the server-side reference, that
it what Control.ResolveUrl takes to produce a client-side reference.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Patrice said:
 
I'm emitting HTML in a control's Render event via writer.Write().

If I emit a path with ~/, that will pass unchanged to the web page.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Eliyahu Goldin said:
Jonathan,

I am not sure why can't you use ~/Images/img.gif as it is. Asp.Net will
compile this reference to Request.ApplicationPath. Obviously, it will work
only for server-side controls, but you can turn any control to a
server-side one by just adding runat=server.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Jonathan Wood said:
I am creating some custom links via code on my Web site.

One problem I have is that I might write a link as /Images/img.gif. On my
Web site, that should work find. But on my local test computer, it is
wrong because / actual refers to the root of my developer server folder.

What I really want is ~/Images/img.gif but I'm not using a label control.
Is there a function that will take ~/Images... and change it to be the
path off my project's root dir? Perhaps the same routine called by the
label controls, etc?

Thanks for any tips.
 
Back
Top