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

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.UriScheme
  • EscapeDataString(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.