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("", "/Images/Image.jpg")

which would return:


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("");
Uri myUri = new Uri(baseUri, "catalog/shownew.htm");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download