System.Uri
Object –> Uri
An object representation of a URI.
Construction
from string
Uri uri = new Uri("https://user:password@www.contoso.com:80/Home/Index.htm?q1=1&q2=v2#FragmentName");
specify base uri or relative uri
Uri uri = new Uri(string "s", UriKind.Absolute); // or UriKind.Relative.
// or
Uri uri = new Uri(Uri baseUri, string "relativeUriString");
// or
Uri uri = new Uri(Uri baseUri, Uri relativeUri);
Fields
Various fields are available for different URI schemes such as File, FTP, SSH, Telnet, etc.
properties
AbsolutePath— /Home/Index.htmAbsoluteUri— https://user:password@www.contoso.com:80/Home/Index.htm?q1=v1&q2=v2#FragmentNameDnsSafeHost— www.contoso.comFragment—#FragmentNameHost— www.contoso.comHostNameType— DnsIdnHost— www.contoso.comIsAbsoluteUri— TrueIsDefaultPort— FalseIsFile— FalseIsLoopback— FalseIsUnc— FalseLocalPath— /Home/Index.htmOriginalString— https://user:password@www.contoso.com:80/Home/Index.htm?q1=v1&q2=v2#FragmentNamePathAndQuery— /Home/Index.htm?q1=v1&q2=v2Port— 80Query— ?q1=v1&q2=v2Scheme— httpsSegments— /, Home/, Index.htmUserEscaped— FalseUserInfo— user:password
methods
CheckHostName(string)— Returns a UriHostNameType indicating if this is a valid hostname or IP address.CheckSchemeName(string)— Boolean if string equals a specific Uri.UriSchemeEscapeDataString(string)— Returns string as an escaped Uri string.IsWellFormedOriginalString()— Boolean if string used to build this Uri was well-formed and properly escaped.IsWellFormedUriString(string, UriKind)— Boolean if string is a well-formed Uri of UriKind.TryCreate(baseUri, relativeUri, out Uri)— Boolean if URI created successfully and stored to Uri.UnescapeDataString(string)— Returns string as an unescaped Uri string.