Path.Combine is handy, but is there a similar function in the .NET framework for URLs?
I'm looking for syntax like this:
Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
which would return:
"http://MyUrl.com/Images/Image.jpg"
asp.netcnetpathurl
Path.Combine is handy, but is there a similar function in the .NET framework for URLs?
I'm looking for syntax like this:
Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
which would return:
"http://MyUrl.com/Images/Image.jpg"
Best Answer
Uri
has a constructor that should do this for you:new Uri(Uri baseUri, string relativeUri)
Here's an example:
Note from editor: Beware, this method does not work as expected. It can cut part of baseUri in some cases. See comments and other answers.