Brian MacKay Brian MacKay -4 years ago 172
ASP.NET (C#) Question

Path.Combine for URLs?

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"

Answer Source

Uri has a constructor that should do this for you: new Uri(Uri baseUri, string relativeUri)

Here's an example:

Uri baseUri = new Uri("http://www.contoso.com");
Uri myUri = new Uri(baseUri, "catalog/shownew.htm");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download