How to build URIs with the UriBuilder class in C#
June 27, 2017 1 Comment
You can normally use the URI object to construct URIs in C#. However, there’s an object called UriBuilder which lets you build up a URI from various elements.
Here’s an example to construct a simple HTTP address with a scheme, a host and a path:
UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Scheme = "http"; uriBuilder.Host = "cnn.com"; uriBuilder.Path = "americas"; Uri uri = uriBuilder.Uri;
uri will be “http://cnn.com/americas”.