views:

67

answers:

2

Hi

I have an html helper library that I am making and one of my plugins needs urls to be passed in. I don't want to pass in the full url since they every-time I change something around I have to go and fix all of the urls up.

How can I get a full Url path in my file? Like if I pass in a relative path or something it gets resolved to a full path.

A: 

You can use HttpCurrent.Context.Server.MapPath(string)

Cleiton
HttpCurrent does not show up for me. I have the System.Web namespace in my file.
chobo2
Ah it is "HttpContext.Current.Server.MapPath"
chobo2
Sorry I guess I should have mentioned this url is used for a picture that I want to display. This gets the whole path but it gets it to my hard drive so it seems not to display.
chobo2
.....the picture
chobo2
+1  A: 

VirtualPathUtility might be a place to look. For example using

VirtualPathUtility.ToAbsolute(src);

will render paths like "~/App/test.jpg" to an absolute location e.g "/VirtualDirectory/App/test.jpg" as well as relative paths. The methods exposed on an instance of the UrlHelper (e.g. Content) class might also be of help.

sighohwell