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