Absolute Paths for Images and Resources in your website from any subdirectory

by rlynch February 12, 2010 09:51

<%=System.Web.VirtualPathUtility.ToAbsolute("~")%>

This solves issues for getting paths for images if you use masterpages that can be consumed by pages in the web root and also from a subdirectory.

1 line of magic!

 

e.g. <a href='<%=System.Web.VirtualPathUtility.ToAbsolute("~")%>/somefile.aspx'>Link to file</a>

or <img src='<%=System.Web.VirtualPathUtility.ToAbsolute("~")%>/images/mylogo.jpg'/>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen | Modified by Mooglegiant

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar