tags:

views:

1228

answers:

3

I have a virtual path (example: "~/Images/Banner.jpg") and I want to make that an absolute web path (example: "/ApplicationRoot/Images/Banner.jpg"). There is a method that will do this, I believe in a class called something like HTTPUtility or similar name. Though ever time I need this method, it takes me hours searching for it. It would be greatly appreciated if someone could post the proper method to do this so I can favorite this for easy access in the future.

Thank you very much.

+8  A: 
System.Web.VirtualPathUtility.ToAbsolute("yourRelativePath");

There you go :)

borisCallens
I actually had the same problem untill I made my own PathHelper class for the asp.net mvc framework :p
borisCallens
Hehe, yet another place to do this! I guess they all end up at the same place.
leppie
I sure hope so :P
borisCallens
This was exactly the method I keep forgetting.. I don't know why it's so hard for me to remember or find this one.
stephenbayer
Thank you again.. It has been a year, I still can't remember that command, and I still go to here every time to remember it.
stephenbayer
+2  A: 
Control.ResolveClientUrl(url)

or

Control.ResolveUrl(url)

Whichever one you need (honestly I dont know the difference, as both seem to return mostly the same, perhaps someone can illuminate me :) ).

leppie
How do you make your verry first line a "code" line?In preview it looks all biscuits and milk, but when I submit it becomes an unformatted line again :s
borisCallens
Double breakline, found it
borisCallens
I didnt have that problem. Using FF.
leppie
+1  A: 

There are various ways that are available in ASP.NET that we can use to resolve relative paths to absolute Urls -

1) Request.ApplicationPath
2) System.Web.VirtualPathUtility
3) Page.ResolveUrl
4) Page.ResolveClientUrl

Here's a article that explains the difference between the various ways to resolving paths in ASP.NET -

Different approaches for resolving URLs in ASP.NET

Rohit Agarwal