ToAbsolute Path from Relative Path

Here is the problem I was solving for…which is quite easy, once I found the right method!

  • Take path “http://myserver.com/folder/page.aspx
  • From here go to ../anotherPage.aspx

VirtualPathUtility.Combine() to the rescue

The VirtualPathUtility class has many useful methods for working with relative and absolute paths. It wasn’t until I found the combine method that I discovered exactly what I was looking for!


VirtualPathUtility.Combine("/myserver.com/folder/page.aspx", "../anotherPage.aspx")

This results in “/myserver.com/anotherPage.aspx”. You can provide any dot notation and it will work perfectly. Hope it saves you some time.

.matti

Advertisement

Tags: , ,

About Matti

Web developer from Akron, OH. ASP.NET, CSS, Mobile Dev and JQuery. Check out my blog @ http://www.relativelypositioned.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.