mscorlib(4.0.0.0) API with additions
System.Uri Class Reference

Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI. More...

Inheritance diagram for System.Uri:
[legend]
Collaboration diagram for System.Uri:
[legend]

Public Member Functions

 Uri (string uriString)
 Initializes a new instance of the T:System.Uri class with the specified URI. More...
 
 Uri (string uriString, bool dontEscape)
 Initializes a new instance of the T:System.Uri class with the specified URI, with explicit control of character escaping. More...
 
 Uri (Uri baseUri, string relativeUri, bool dontEscape)
 Initializes a new instance of the T:System.Uri class based on the specified base and relative URIs, with explicit control of character escaping. More...
 
 Uri (string uriString, UriKind uriKind)
 Initializes a new instance of the T:System.Uri class with the specified URI. This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate. More...
 
 Uri (Uri baseUri, string relativeUri)
 Initializes a new instance of the T:System.Uri class based on the specified base URI and relative URI string. More...
 
 Uri (Uri baseUri, Uri relativeUri)
 Initializes a new instance of the T:System.Uri class based on the combination of a specified base T:System.Uri instance and a relative T:System.Uri instance. More...
 
string GetLeftPart (UriPartial part)
 Gets the specified portion of a T:System.Uri instance. More...
 
override int GetHashCode ()
 Gets the hash code for the URI. More...
 
override string ToString ()
 Gets a canonical string representation for the specified T:System.Uri instance. More...
 
unsafe override bool Equals (object comparand)
 Compares two T:System.Uri instances for equality. More...
 
Uri MakeRelativeUri (Uri uri)
 Determines the difference between two T:System.Uri instances. More...
 
string MakeRelative (Uri toUri)
 Determines the difference between two T:System.Uri instances. More...
 
string GetComponents (UriComponents components, UriFormat format)
 Gets the specified components of the current instance using the specified escaping for special characters. More...
 
bool IsWellFormedOriginalString ()
 Indicates whether the string used to construct this T:System.Uri was well-formed and is not required to be further escaped. More...
 
bool IsBaseOf (Uri uri)
 Determines whether the current T:System.Uri instance is a base of the specified T:System.Uri instance. More...
 

Static Public Member Functions

static unsafe UriHostNameType CheckHostName (string name)
 Determines whether the specified host name is a valid DNS name. More...
 
static string HexEscape (char character)
 Converts a specified character into its hexadecimal equivalent. More...
 
static char HexUnescape (string pattern, ref int index)
 Converts a specified hexadecimal representation of a character to the character. More...
 
static bool IsHexEncoding (string pattern, int index)
 Determines whether a character in a string is hexadecimal encoded. More...
 
static bool CheckSchemeName (string schemeName)
 Determines whether the specified scheme name is valid. More...
 
static bool IsHexDigit (char character)
 Determines whether a specified character is a valid hexadecimal digit. More...
 
static int FromHex (char digit)
 Gets the decimal value of a hexadecimal digit. More...
 
static bool operator== (Uri uri1, Uri uri2)
 Determines whether two T:System.Uri instances have the same value. More...
 
static bool operator != (Uri uri1, Uri uri2)
 Determines whether two T:System.Uri instances do not have the same value. More...
 
static bool TryCreate (string uriString, UriKind uriKind, out Uri result)
 Creates a new T:System.Uri using the specified T:System.String instance and a T:System.UriKind. More...
 
static bool TryCreate (Uri baseUri, string relativeUri, out Uri result)
 Creates a new T:System.Uri using the specified base and relative T:System.String instances. More...
 
static bool TryCreate (Uri baseUri, Uri relativeUri, out Uri result)
 Creates a new T:System.Uri using the specified base and relative T:System.Uri instances. More...
 
static int Compare (Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, StringComparison comparisonType)
 Compares the specified parts of two URIs using the specified comparison rules. More...
 
static bool IsWellFormedUriString (string uriString, UriKind uriKind)
 Indicates whether the string is well-formed by attempting to construct a URI with the string and ensures that the string does not require further escaping. More...
 
static unsafe string UnescapeDataString (string stringToUnescape)
 Converts a string to its unescaped representation. More...
 
static string EscapeUriString (string stringToEscape)
 Converts a URI string to its escaped representation. More...
 
static string EscapeDataString (string stringToEscape)
 Converts a string to its escaped representation. More...
 

Static Public Attributes

static readonly string UriSchemeFile = UriParser.FileUri.SchemeName
 Specifies that the URI is a pointer to a file. This field is read-only. More...
 
static readonly string UriSchemeFtp = UriParser.FtpUri.SchemeName
 Specifies that the URI is accessed through the File Transfer Protocol (FTP). This field is read-only. More...
 
static readonly string UriSchemeGopher = UriParser.GopherUri.SchemeName
 Specifies that the URI is accessed through the Gopher protocol. This field is read-only. More...
 
static readonly string UriSchemeHttp = UriParser.HttpUri.SchemeName
 Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). This field is read-only. More...
 
static readonly string UriSchemeHttps = UriParser.HttpsUri.SchemeName
 Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS). This field is read-only. More...
 
static readonly string UriSchemeMailto = UriParser.MailToUri.SchemeName
 Specifies that the URI is an e-mail address and is accessed through the Simple Mail Transport Protocol (SMTP). This field is read-only. More...
 
static readonly string UriSchemeNews = UriParser.NewsUri.SchemeName
 Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only. More...
 
static readonly string UriSchemeNntp = UriParser.NntpUri.SchemeName
 Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only. More...
 
static readonly string UriSchemeNetTcp = UriParser.NetTcpUri.SchemeName
 Specifies that the URI is accessed through the NetTcp scheme used by Windows Communication Foundation (WCF). This field is read-only. More...
 
static readonly string UriSchemeNetPipe = UriParser.NetPipeUri.SchemeName
 Specifies that the URI is accessed through the NetPipe scheme used by Windows Communication Foundation (WCF). This field is read-only. More...
 
static readonly string SchemeDelimiter = "://"
 Specifies the characters that separate the communication protocol scheme from the address portion of the URI. This field is read-only. More...
 

Protected Member Functions

 Uri (SerializationInfo serializationInfo, StreamingContext streamingContext)
 Initializes a new instance of the T:System.Uri class from the specified instances of the T:System.Runtime.Serialization.SerializationInfo and T:System.Runtime.Serialization.StreamingContext classes. More...
 
void GetObjectData (SerializationInfo serializationInfo, StreamingContext streamingContext)
 Returns the data needed to serialize the current instance. More...
 
virtual void Parse ()
 Parses the URI of the current instance to ensure it contains all the parts required for a valid URI. More...
 
virtual void Canonicalize ()
 Converts the internally stored URI to canonical form. More...
 
virtual void Escape ()
 Converts any unsafe or reserved characters in the path component to their hexadecimal character representations. More...
 
virtual string Unescape (string path)
 Converts the specified string by replacing any escape sequences with their unescaped representation. More...
 
virtual void CheckSecurity ()
 Calling this method has no effect. More...
 
virtual bool IsReservedCharacter (char character)
 Gets whether the specified character is a reserved character. More...
 
virtual bool IsBadFileSystemCharacter (char character)
 Gets whether a character is invalid in a file system name. More...
 

Static Protected Member Functions

static string EscapeString (string str)
 Converts a string to its escaped representation. More...
 
static bool IsExcludedCharacter (char character)
 Gets whether the specified character should be escaped. More...
 

Properties

string AbsolutePath [get]
 Gets the absolute path of the URI. More...
 
string AbsoluteUri [get]
 Gets the absolute URI. More...
 
string LocalPath [get]
 Gets a local operating-system representation of a file name. More...
 
string Authority [get]
 Gets the Domain Name System (DNS) host name or IP address and the port number for a server. More...
 
UriHostNameType HostNameType [get]
 Gets the type of the host name specified in the URI. More...
 
bool IsDefaultPort [get]
 Gets whether the port value of the URI is the default for this scheme. More...
 
bool IsFile [get]
 Gets a value indicating whether the specified T:System.Uri is a file URI. More...
 
bool IsLoopback [get]
 Gets whether the specified T:System.Uri references the local host. More...
 
string PathAndQuery [get]
 Gets the P:System.Uri.AbsolutePath and P:System.Uri.Query properties separated by a question mark (?). More...
 
string [] Segments [get]
 Gets an array containing the path segments that make up the specified URI. More...
 
bool IsUnc [get]
 Gets whether the specified T:System.Uri is a universal naming convention (UNC) path. More...
 
string Host [get]
 Gets the host component of this instance. More...
 
int Port [get]
 Gets the port number of this URI. More...
 
string Query [get]
 Gets any query information included in the specified URI. More...
 
string Fragment [get]
 Gets the escaped URI fragment. More...
 
string Scheme [get]
 Gets the scheme name for this URI. More...
 
string OriginalString [get]
 Gets the original URI string that was passed to the T:System.Uri constructor. More...
 
string DnsSafeHost [get]
 Gets an unescaped host name that is safe to use for DNS resolution. More...
 
string IdnHost [get]
 The RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate. More...
 
bool IsAbsoluteUri [get]
 Gets whether the T:System.Uri instance is absolute. More...
 
bool UserEscaped [get]
 Indicates that the URI string was completely escaped before the T:System.Uri instance was created. More...
 
string UserInfo [get]
 Gets the user name, password, or other user-specific information associated with the specified URI. More...
 

Detailed Description

Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.

Definition at line 19 of file Uri.cs.

Constructor & Destructor Documentation

◆ Uri() [1/7]

System.Uri.Uri ( string  uriString)

Initializes a new instance of the T:System.Uri class with the specified URI.

Parameters
uriStringA URI.
Exceptions
T:System.ArgumentNullExceptionuriString is null.
T:System.UriFormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, T:System.FormatException, instead. uriString is empty.-or- The scheme specified in uriString is not correctly formed. See M:System.Uri.CheckSchemeName(System.String).-or- uriString contains too many slashes.-or- The password specified in uriString is not valid.-or- The host name specified in uriString is not valid.-or- The file name specified in uriString is not valid. -or- The user name specified in uriString is not valid.-or- The host or authority name specified in uriString cannot be terminated by backslashes.-or- The port number specified in uriString is not valid or cannot be parsed.-or- The length of uriString exceeds 65519 characters.-or- The length of the scheme specified in uriString exceeds 1023 characters.-or- There is an invalid character sequence in uriString .-or- The MS-DOS path specified in uriString must start with c:\.

Definition at line 1013 of file Uri.cs.

◆ Uri() [2/7]

System.Uri.Uri ( string  uriString,
bool  dontEscape 
)

Initializes a new instance of the T:System.Uri class with the specified URI, with explicit control of character escaping.

Parameters
uriStringThe URI.
dontEscapetrue if uriString is completely escaped; otherwise, false. See Remarks.
Exceptions
T:System.ArgumentNullExceptionuriString is null.
T:System.UriFormatExceptionuriString is empty or contains only spaces.-or- The scheme specified in uriString is not valid.-or- uriString contains too many slashes.-or- The password specified in uriString is not valid.-or- The host name specified in uriString is not valid.-or- The file name specified in uriString is not valid. -or- The user name specified in uriString is not valid.-or- The host or authority name specified in uriString cannot be terminated by backslashes.-or- The port number specified in uriString is not valid or cannot be parsed.-or- The length of uriString exceeds 65519 characters.-or- The length of the scheme specified in uriString exceeds 1023 characters.-or- There is an invalid character sequence in uriString .-or- The MS-DOS path specified in uriString must start with c:\.

Definition at line 1032 of file Uri.cs.

◆ Uri() [3/7]

System.Uri.Uri ( Uri  baseUri,
string  relativeUri,
bool  dontEscape 
)

Initializes a new instance of the T:System.Uri class based on the specified base and relative URIs, with explicit control of character escaping.

Parameters
baseUriThe base URI.
relativeUriThe relative URI to add to the base URI.
dontEscapetrue if uriString is completely escaped; otherwise, false. See Remarks.
Exceptions
T:System.ArgumentNullExceptionbaseUri is null.
T:System.ArgumentOutOfRangeExceptionbaseUri is not an absolute T:System.Uri instance.
T:System.UriFormatExceptionThe URI formed by combining baseUri and relativeUri is empty or contains only spaces.-or- The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The URI formed by combining baseUri and relativeUri contains too many slashes.-or- The password specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The host name specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The file name specified in the URI formed by combining baseUri and relativeUri is not valid. -or- The user name specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The host or authority name specified in the URI formed by combining baseUri and relativeUri cannot be terminated by backslashes.-or- The port number specified in the URI formed by combining baseUri and relativeUri is not valid or cannot be parsed.-or- The length of the URI formed by combining baseUri and relativeUri exceeds 65519 characters.-or- The length of the scheme specified in the URI formed by combining baseUri and relativeUri exceeds 1023 characters.-or- There is an invalid character sequence in the URI formed by combining baseUri and relativeUri .-or- The MS-DOS path specified in uriString must start with c:\.

Definition at line 1052 of file Uri.cs.

◆ Uri() [4/7]

System.Uri.Uri ( string  uriString,
UriKind  uriKind 
)

Initializes a new instance of the T:System.Uri class with the specified URI. This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate.

Parameters
uriStringA string that identifies the resource to be represented by the T:System.Uri instance.
uriKindSpecifies whether the URI string is a relative URI, absolute URI, or is indeterminate.
Exceptions
T:System.ArgumentExceptionuriKind is invalid.
T:System.ArgumentNullExceptionuriString is null.
T:System.UriFormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, T:System.FormatException, instead. uriString contains a relative URI and uriKind is F:System.UriKind.Absolute.or uriString contains an absolute URI and uriKind is F:System.UriKind.Relative.or uriString is empty.-or- The scheme specified in uriString is not correctly formed. See M:System.Uri.CheckSchemeName(System.String).-or- uriString contains too many slashes.-or- The password specified in uriString is not valid.-or- The host name specified in uriString is not valid.-or- The file name specified in uriString is not valid. -or- The user name specified in uriString is not valid.-or- The host or authority name specified in uriString cannot be terminated by backslashes.-or- The port number specified in uriString is not valid or cannot be parsed.-or- The length of uriString exceeds 65519 characters.-or- The length of the scheme specified in uriString exceeds 1023 characters.-or- There is an invalid character sequence in uriString .-or- The MS-DOS path specified in uriString must start with c:\.

Definition at line 1079 of file Uri.cs.

◆ Uri() [5/7]

System.Uri.Uri ( Uri  baseUri,
string  relativeUri 
)

Initializes a new instance of the T:System.Uri class based on the specified base URI and relative URI string.

Parameters
baseUriThe base URI.
relativeUriThe relative URI to add to the base URI.
Exceptions
T:System.ArgumentNullExceptionbaseUri is null.
T:System.ArgumentOutOfRangeExceptionbaseUri is not an absolute T:System.Uri instance.
T:System.UriFormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, T:System.FormatException, instead.The URI formed by combining baseUri and relativeUri is empty or contains only spaces.-or- The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The URI formed by combining baseUri and relativeUri contains too many slashes.-or- The password specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The host name specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The file name specified in the URI formed by combining baseUri and relativeUri is not valid. -or- The user name specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The host or authority name specified in the URI formed by combining baseUri and relativeUri cannot be terminated by backslashes.-or- The port number specified in the URI formed by combining baseUri and relativeUri is not valid or cannot be parsed.-or- The length of the URI formed by combining baseUri and relativeUri exceeds 65519 characters.-or- The length of the scheme specified in the URI formed by combining baseUri and relativeUri exceeds 1023 characters.-or- There is an invalid character sequence in the URI formed by combining baseUri and relativeUri .-or- The MS-DOS path specified in uriString must start with c:\.

Definition at line 1098 of file Uri.cs.

◆ Uri() [6/7]

System.Uri.Uri ( Uri  baseUri,
Uri  relativeUri 
)

Initializes a new instance of the T:System.Uri class based on the combination of a specified base T:System.Uri instance and a relative T:System.Uri instance.

Parameters
baseUriAn absolute T:System.Uri that is the base for the new T:System.Uri instance.
relativeUriA relative T:System.Uri instance that is combined with baseUri .
Exceptions
T:System.ArgumentExceptionbaseUri is not an absolute T:System.Uri instance.
T:System.ArgumentNullExceptionbaseUri is null.
T:System.ArgumentOutOfRangeExceptionbaseUri is not an absolute T:System.Uri instance.
T:System.UriFormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, T:System.FormatException, instead.The URI formed by combining baseUri and relativeUri is empty or contains only spaces.-or- The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The URI formed by combining baseUri and relativeUri contains too many slashes.-or- The password specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The host name specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The file name specified in the URI formed by combining baseUri and relativeUri is not valid. -or- The user name specified in the URI formed by combining baseUri and relativeUri is not valid.-or- The host or authority name specified in the URI formed by combining baseUri and relativeUri cannot be terminated by backslashes.-or- The port number specified in the URI formed by combining baseUri and relativeUri is not valid or cannot be parsed.-or- The length of the URI formed by combining baseUri and relativeUri exceeds 65519 characters.-or- The length of the scheme specified in the URI formed by combining baseUri and relativeUri exceeds 1023 characters.-or- There is an invalid character sequence in the URI formed by combining baseUri and relativeUri .-or- The MS-DOS path specified in uriString must start with c:\.

Definition at line 1158 of file Uri.cs.

◆ Uri() [7/7]

System.Uri.Uri ( SerializationInfo  serializationInfo,
StreamingContext  streamingContext 
)
protected

Initializes a new instance of the T:System.Uri class from the specified instances of the T:System.Runtime.Serialization.SerializationInfo and T:System.Runtime.Serialization.StreamingContext classes.

Parameters
serializationInfoAn instance of the T:System.Runtime.Serialization.SerializationInfo class containing the information required to serialize the new T:System.Uri instance.
streamingContextAn instance of the T:System.Runtime.Serialization.StreamingContext class containing the source of the serialized stream associated with the new T:System.Uri instance.
Exceptions
T:System.ArgumentNullExceptionThe serializationInfo parameter contains a null URI.
T:System.UriFormatExceptionThe serializationInfo parameter contains a URI that is empty.-or- The scheme specified is not correctly formed. See M:System.Uri.CheckSchemeName(System.String).-or- The URI contains too many slashes.-or- The password specified in the URI is not valid.-or- The host name specified in URI is not valid.-or- The file name specified in the URI is not valid. -or- The user name specified in the URI is not valid.-or- The host or authority name specified in the URI cannot be terminated by backslashes.-or- The port number specified in the URI is not valid or cannot be parsed.-or- The length of URI exceeds 65519 characters.-or- The length of the scheme specified in the URI exceeds 1023 characters.-or- There is an invalid character sequence in the URI.-or- The MS-DOS path specified in the URI must start with c:\.

Definition at line 1279 of file Uri.cs.

Member Function Documentation

◆ Canonicalize()

virtual void System.Uri.Canonicalize ( )
protectedvirtual

Converts the internally stored URI to canonical form.

Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this method is valid only for absolute URIs.
T:System.UriFormatExceptionThe URI is incorrectly formed.

Definition at line 4491 of file Uri.cs.

◆ CheckHostName()

static unsafe UriHostNameType System.Uri.CheckHostName ( string  name)
static

Determines whether the specified host name is a valid DNS name.

Parameters
nameThe host name to validate. This can be an IPv4 or IPv6 address or an Internet host name.
Returns
A T:System.UriHostNameType that indicates the type of the host name. If the type of the host name cannot be determined or if the host name is null or a zero-length string, this method returns F:System.UriHostNameType.Unknown.

Definition at line 1431 of file Uri.cs.

◆ CheckSchemeName()

static bool System.Uri.CheckSchemeName ( string  schemeName)
static

Determines whether the specified scheme name is valid.

Parameters
schemeNameThe scheme name to validate.
Returns
A T:System.Boolean value that is true if the scheme name is valid; otherwise, false.

Definition at line 1576 of file Uri.cs.

◆ CheckSecurity()

virtual void System.Uri.CheckSecurity ( )
protectedvirtual

Calling this method has no effect.

Definition at line 4535 of file Uri.cs.

◆ Compare()

static int System.Uri.Compare ( Uri  uri1,
Uri  uri2,
UriComponents  partsToCompare,
UriFormat  compareFormat,
StringComparison  comparisonType 
)
static

Compares the specified parts of two URIs using the specified comparison rules.

Parameters
uri1The first T:System.Uri.
uri2The second T:System.Uri.
partsToCompareA bitwise combination of the T:System.UriComponents values that specifies the parts of uri1 and uri2 to compare.
compareFormatOne of the T:System.UriFormat values that specifies the character escaping used when the URI components are compared.
comparisonTypeOne of the T:System.StringComparison values.
Returns
An T:System.Int32 value that indicates the lexical relationship between the compared T:System.Uri components.ValueMeaningLess than zero uri1 is less than uri2 .Zero uri1 equals uri2 .Greater than zero uri1 is greater than uri2 .
Exceptions
T:System.ArgumentExceptioncomparisonType is not a valid T:System.StringComparison value.

Definition at line 4912 of file Uri.cs.

◆ Equals()

unsafe override bool System.Uri.Equals ( object  comparand)

Compares two T:System.Uri instances for equality.

Parameters
comparandThe T:System.Uri instance or a URI identifier to compare with the current instance.
Returns
A T:System.Boolean value that is true if the two instances represent the same URI; otherwise, false.

Definition at line 1731 of file Uri.cs.

◆ Escape()

virtual void System.Uri.Escape ( )
protectedvirtual

Converts any unsafe or reserved characters in the path component to their hexadecimal character representations.

Exceptions
T:System.UriFormatExceptionThe URI passed from the constructor is invalid. This exception can occur if a URI has too many characters or the URI is relative.

Definition at line 4498 of file Uri.cs.

◆ EscapeDataString()

static string System.Uri.EscapeDataString ( string  stringToEscape)
static

Converts a string to its escaped representation.

Parameters
stringToEscapeThe string to escape.
Returns
A T:System.String that contains the escaped representation of stringToEscape .
Exceptions
T:System.ArgumentNullExceptionstringToEscape is null.
T:System.UriFormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, T:System.FormatException, instead.The length of stringToEscape exceeds 32766 characters.

Definition at line 5117 of file Uri.cs.

◆ EscapeString()

static string System.Uri.EscapeString ( string  str)
staticprotected

Converts a string to its escaped representation.

Parameters
strThe string to transform to its escaped representation.
Returns
The escaped representation of the string.

Definition at line 4518 of file Uri.cs.

◆ EscapeUriString()

static string System.Uri.EscapeUriString ( string  stringToEscape)
static

Converts a URI string to its escaped representation.

Parameters
stringToEscapeThe string to escape.
Returns
A T:System.String that contains the escaped representation of stringToEscape .
Exceptions
T:System.ArgumentNullExceptionstringToEscape is null.
T:System.UriFormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, T:System.FormatException, instead.The length of stringToEscape exceeds 32766 characters.

Definition at line 5090 of file Uri.cs.

◆ FromHex()

static int System.Uri.FromHex ( char  digit)
static

Gets the decimal value of a hexadecimal digit.

Parameters
digitThe hexadecimal digit (0-9, a-f, A-F) to convert.
Returns
An T:System.Int32 value that contains a number from 0 to 15 that corresponds to the specified hexadecimal digit.
Exceptions
T:System.ArgumentExceptiondigit is not a valid hexadecimal digit (0-9, a-f, A-F).

Definition at line 1613 of file Uri.cs.

◆ GetComponents()

string System.Uri.GetComponents ( UriComponents  components,
UriFormat  format 
)

Gets the specified components of the current instance using the specified escaping for special characters.

Parameters
componentsA bitwise combination of the T:System.UriComponents values that specifies which parts of the current instance to return to the caller.
formatOne of the T:System.UriFormat values that controls how special characters are escaped.
Returns
A T:System.String that contains the components.
Exceptions
T:System.ArgumentOutOfRangeExceptioncomponents is not a combination of valid T:System.UriComponents values.
T:System.InvalidOperationExceptionThe current T:System.Uri is not an absolute URI. Relative URIs cannot be used with this method.

Definition at line 4874 of file Uri.cs.

◆ GetHashCode()

override int System.Uri.GetHashCode ( )

Gets the hash code for the URI.

Returns
An T:System.Int32 containing the hash value generated for this URI.

Definition at line 1630 of file Uri.cs.

◆ GetLeftPart()

string System.Uri.GetLeftPart ( UriPartial  part)

Gets the specified portion of a T:System.Uri instance.

Parameters
partOne of the T:System.UriPartial values that specifies the end of the URI portion to return.
Returns
A T:System.String that contains the specified portion of the T:System.Uri instance.
Exceptions
T:System.InvalidOperationExceptionThe current T:System.Uri instance is not an absolute instance.
T:System.ArgumentExceptionThe specified part is not valid.

Definition at line 1479 of file Uri.cs.

◆ GetObjectData()

void System.Uri.GetObjectData ( SerializationInfo  serializationInfo,
StreamingContext  streamingContext 
)
protected

Returns the data needed to serialize the current instance.

Parameters
serializationInfoA T:System.Runtime.Serialization.SerializationInfo object containing the information required to serialize the T:System.Uri.
streamingContextA T:System.Runtime.Serialization.StreamingContext object containing the source and destination of the serialized stream associated with the T:System.Uri.

Implements System.Runtime.Serialization.ISerializable.

Definition at line 1308 of file Uri.cs.

◆ HexEscape()

static string System.Uri.HexEscape ( char  character)
static

Converts a specified character into its hexadecimal equivalent.

Parameters
characterThe character to convert to hexadecimal representation.
Returns
The hexadecimal representation of the specified character.
Exceptions
T:System.ArgumentOutOfRangeExceptioncharacter is greater than 255.

Definition at line 1510 of file Uri.cs.

◆ HexUnescape()

static char System.Uri.HexUnescape ( string  pattern,
ref int  index 
)
static

Converts a specified hexadecimal representation of a character to the character.

Parameters
patternThe hexadecimal representation of a character.
indexThe location in pattern where the hexadecimal representation of a character begins.
Returns
The character represented by the hexadecimal encoding at position index . If the character at index is not hexadecimal encoded, the character at index is returned. The value of index is incremented to point to the character following the one returned.
Exceptions
T:System.ArgumentOutOfRangeExceptionindex is less than 0 or greater than or equal to the number of characters in pattern .

Definition at line 1528 of file Uri.cs.

◆ IsBadFileSystemCharacter()

virtual bool System.Uri.IsBadFileSystemCharacter ( char  character)
protectedvirtual

Gets whether a character is invalid in a file system name.

Parameters
characterThe T:System.Char to test.
Returns
A T:System.Boolean value that is true if the specified character is invalid; otherwise false.

Definition at line 4570 of file Uri.cs.

◆ IsBaseOf()

bool System.Uri.IsBaseOf ( Uri  uri)

Determines whether the current T:System.Uri instance is a base of the specified T:System.Uri instance.

Parameters
uriThe specified T:System.Uri instance to test.
Returns
true if the current T:System.Uri instance is a base of uri ; otherwise, false.
Exceptions
T:System.ArgumentNullExceptionuri is null.

Definition at line 5343 of file Uri.cs.

◆ IsExcludedCharacter()

static bool System.Uri.IsExcludedCharacter ( char  character)
staticprotected

Gets whether the specified character should be escaped.

Parameters
characterThe T:System.Char to test.
Returns
A T:System.Boolean value that is true if the specified character should be escaped; otherwise, false.

Definition at line 4557 of file Uri.cs.

◆ IsHexDigit()

static bool System.Uri.IsHexDigit ( char  character)
static

Determines whether a specified character is a valid hexadecimal digit.

Parameters
characterThe character to validate.
Returns
A T:System.Boolean value that is true if the character is a valid hexadecimal digit; otherwise false.

Definition at line 1595 of file Uri.cs.

◆ IsHexEncoding()

static bool System.Uri.IsHexEncoding ( string  pattern,
int  index 
)
static

Determines whether a character in a string is hexadecimal encoded.

Parameters
patternThe string to check.
indexThe location in pattern to check for hexadecimal encoding.
Returns
A T:System.Boolean value that is true if pattern is hexadecimal encoded at the specified location; otherwise, false.

Definition at line 1550 of file Uri.cs.

◆ IsReservedCharacter()

virtual bool System.Uri.IsReservedCharacter ( char  character)
protectedvirtual

Gets whether the specified character is a reserved character.

Parameters
characterThe T:System.Char to test.
Returns
A T:System.Boolean value that is true if the specified character is a reserved character otherwise, false.

Definition at line 4544 of file Uri.cs.

◆ IsWellFormedOriginalString()

bool System.Uri.IsWellFormedOriginalString ( )

Indicates whether the string used to construct this T:System.Uri was well-formed and is not required to be further escaped.

Returns
A T:System.Boolean value that is true if the string was well-formed; else false.

Definition at line 4944 of file Uri.cs.

◆ IsWellFormedUriString()

static bool System.Uri.IsWellFormedUriString ( string  uriString,
UriKind  uriKind 
)
static

Indicates whether the string is well-formed by attempting to construct a URI with the string and ensures that the string does not require further escaping.

Parameters
uriStringThe string used to attempt to construct a T:System.Uri.
uriKindThe type of the T:System.Uri in uriString .
Returns
A T:System.Boolean value that is true if the string was well-formed; else false.

Definition at line 4958 of file Uri.cs.

◆ MakeRelative()

string System.Uri.MakeRelative ( Uri  toUri)

Determines the difference between two T:System.Uri instances.

Parameters
toUriThe URI to compare to the current URI.
Returns
If the hostname and scheme of this URI instance and toUri are the same, then this method returns a T:System.String that represents a relative URI that, when appended to the current URI instance, yields the toUri parameter.If the hostname or scheme is different, then this method returns a T:System.String that represents the toUri parameter.
Exceptions
T:System.ArgumentNullExceptiontoUri is null.
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this method is valid only for absolute URIs.

Definition at line 4463 of file Uri.cs.

◆ MakeRelativeUri()

Uri System.Uri.MakeRelativeUri ( Uri  uri)

Determines the difference between two T:System.Uri instances.

Parameters
uriThe URI to compare to the current URI.
Returns
If the hostname and scheme of this URI instance and uri are the same, then this method returns a relative T:System.Uri that, when appended to the current URI instance, yields uri .If the hostname or scheme is different, then this method returns a T:System.Uri that represents the uri parameter.
Exceptions
T:System.ArgumentNullExceptionuri is null.
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 1900 of file Uri.cs.

◆ operator !=()

static bool System.Uri.operator != ( Uri  uri1,
Uri  uri2 
)
static

Determines whether two T:System.Uri instances do not have the same value.

Parameters
uri1A T:System.Uri instance to compare with uri2 .
uri2A T:System.Uri instance to compare with uri1 .
Returns
A T:System.Boolean value that is true if the two T:System.Uri instances are not equal; otherwise, false. If either parameter is null, this method returns true.

Definition at line 1713 of file Uri.cs.

◆ operator==()

static bool System.Uri.operator== ( Uri  uri1,
Uri  uri2 
)
static

Determines whether two T:System.Uri instances have the same value.

Parameters
uri1A T:System.Uri instance to compare with uri2 .
uri2A T:System.Uri instance to compare with uri1 .
Returns
A T:System.Boolean value that is true if the T:System.Uri instances are equivalent; otherwise, false.

Definition at line 1694 of file Uri.cs.

◆ Parse()

virtual void System.Uri.Parse ( )
protectedvirtual

Parses the URI of the current instance to ensure it contains all the parts required for a valid URI.

Exceptions
T:System.UriFormatExceptionThe Uri passed from the constructor is invalid.

Definition at line 4483 of file Uri.cs.

◆ ToString()

override string System.Uri.ToString ( )

Gets a canonical string representation for the specified T:System.Uri instance.

Returns
A T:System.String instance that contains the unescaped canonical representation of the T:System.Uri instance. All characters are unescaped except #, ?, and %.

Definition at line 1663 of file Uri.cs.

◆ TryCreate() [1/3]

static bool System.Uri.TryCreate ( string  uriString,
UriKind  uriKind,
out Uri  result 
)
static

Creates a new T:System.Uri using the specified T:System.String instance and a T:System.UriKind.

Parameters
uriStringThe T:System.String representing the T:System.Uri.
uriKindThe type of the Uri.
resultWhen this method returns, contains the constructed T:System.Uri.
Returns
A T:System.Boolean value that is true if the T:System.Uri was successfully created; otherwise, false.

Definition at line 4782 of file Uri.cs.

◆ TryCreate() [2/3]

static bool System.Uri.TryCreate ( Uri  baseUri,
string  relativeUri,
out Uri  result 
)
static

Creates a new T:System.Uri using the specified base and relative T:System.String instances.

Parameters
baseUriThe base T:System.Uri.
relativeUriThe relative T:System.Uri, represented as a T:System.String, to add to the base T:System.Uri.
resultWhen this method returns, contains a T:System.Uri constructed from baseUri and relativeUri . This parameter is passed uninitialized.
Returns
A T:System.Boolean value that is true if the T:System.Uri was successfully created; otherwise, false.

Definition at line 4804 of file Uri.cs.

◆ TryCreate() [3/3]

static bool System.Uri.TryCreate ( Uri  baseUri,
Uri  relativeUri,
out Uri  result 
)
static

Creates a new T:System.Uri using the specified base and relative T:System.Uri instances.

Parameters
baseUriThe base T:System.Uri.
relativeUriThe relative T:System.Uri to add to the base T:System.Uri.
resultWhen this method returns, contains a T:System.Uri constructed from baseUri and relativeUri . This parameter is passed uninitialized.
Returns
A T:System.Boolean value that is true if the T:System.Uri was successfully created; otherwise, false.
Exceptions
T:System.ArgumentNullExceptionbaseUri is null.

Definition at line 4827 of file Uri.cs.

◆ Unescape()

virtual string System.Uri.Unescape ( string  path)
protectedvirtual

Converts the specified string by replacing any escape sequences with their unescaped representation.

Parameters
pathThe T:System.String to convert.
Returns
A T:System.String that contains the unescaped value of the path parameter.

Definition at line 4506 of file Uri.cs.

◆ UnescapeDataString()

static unsafe string System.Uri.UnescapeDataString ( string  stringToUnescape)
static

Converts a string to its unescaped representation.

Parameters
stringToUnescapeThe string to unescape.
Returns
A T:System.String that contains the unescaped representation of stringToUnescape .
Exceptions
T:System.ArgumentNullExceptionstringToUnescape is null.

Definition at line 5054 of file Uri.cs.

Member Data Documentation

◆ SchemeDelimiter

readonly string System.Uri.SchemeDelimiter = "://"
static

Specifies the characters that separate the communication protocol scheme from the address portion of the URI. This field is read-only.

Definition at line 179 of file Uri.cs.

◆ UriSchemeFile

readonly string System.Uri.UriSchemeFile = UriParser.FileUri.SchemeName
static

Specifies that the URI is a pointer to a file. This field is read-only.

Definition at line 145 of file Uri.cs.

◆ UriSchemeFtp

readonly string System.Uri.UriSchemeFtp = UriParser.FtpUri.SchemeName
static

Specifies that the URI is accessed through the File Transfer Protocol (FTP). This field is read-only.

Definition at line 148 of file Uri.cs.

◆ UriSchemeGopher

readonly string System.Uri.UriSchemeGopher = UriParser.GopherUri.SchemeName
static

Specifies that the URI is accessed through the Gopher protocol. This field is read-only.

Definition at line 151 of file Uri.cs.

◆ UriSchemeHttp

readonly string System.Uri.UriSchemeHttp = UriParser.HttpUri.SchemeName
static

Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). This field is read-only.

Definition at line 154 of file Uri.cs.

◆ UriSchemeHttps

readonly string System.Uri.UriSchemeHttps = UriParser.HttpsUri.SchemeName
static

Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS). This field is read-only.

Definition at line 157 of file Uri.cs.

◆ UriSchemeMailto

readonly string System.Uri.UriSchemeMailto = UriParser.MailToUri.SchemeName
static

Specifies that the URI is an e-mail address and is accessed through the Simple Mail Transport Protocol (SMTP). This field is read-only.

Definition at line 164 of file Uri.cs.

◆ UriSchemeNetPipe

readonly string System.Uri.UriSchemeNetPipe = UriParser.NetPipeUri.SchemeName
static

Specifies that the URI is accessed through the NetPipe scheme used by Windows Communication Foundation (WCF). This field is read-only.

Definition at line 176 of file Uri.cs.

◆ UriSchemeNetTcp

readonly string System.Uri.UriSchemeNetTcp = UriParser.NetTcpUri.SchemeName
static

Specifies that the URI is accessed through the NetTcp scheme used by Windows Communication Foundation (WCF). This field is read-only.

Definition at line 173 of file Uri.cs.

◆ UriSchemeNews

readonly string System.Uri.UriSchemeNews = UriParser.NewsUri.SchemeName
static

Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.

Definition at line 167 of file Uri.cs.

◆ UriSchemeNntp

readonly string System.Uri.UriSchemeNntp = UriParser.NntpUri.SchemeName
static

Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.

Definition at line 170 of file Uri.cs.

Property Documentation

◆ AbsolutePath

string System.Uri.AbsolutePath
get

Gets the absolute path of the URI.

Returns
A T:System.String containing the absolute path to the resource.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 303 of file Uri.cs.

◆ AbsoluteUri

string System.Uri.AbsoluteUri
get

Gets the absolute URI.

Returns
A T:System.String containing the entire URI.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 344 of file Uri.cs.

◆ Authority

string System.Uri.Authority
get

Gets the Domain Name System (DNS) host name or IP address and the port number for a server.

Returns
A T:System.String containing the authority component of the URI represented by this instance.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 389 of file Uri.cs.

◆ DnsSafeHost

string System.Uri.DnsSafeHost
get

Gets an unescaped host name that is safe to use for DNS resolution.

Returns
A T:System.String that contains the unescaped host part of the URI that is suitable for DNS resolution; or the original unescaped host string, if it is already suitable for resolution.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 756 of file Uri.cs.

◆ Fragment

string System.Uri.Fragment
get

Gets the escaped URI fragment.

Returns
A T:System.String that contains any URI fragment information.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 674 of file Uri.cs.

◆ Host

string System.Uri.Host
get

Gets the host component of this instance.

Returns
A T:System.String that contains the host name. This is usually the DNS host name or IP address of the server.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 587 of file Uri.cs.

◆ HostNameType

UriHostNameType System.Uri.HostNameType
get

Gets the type of the host name specified in the URI.

Returns
A member of the T:System.UriHostNameType enumeration.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 406 of file Uri.cs.

◆ IdnHost

string System.Uri.IdnHost
get

The RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate.

Returns
Returns the hostname, formatted with Punycode according to the IDN standard.T:System.String.

Definition at line 803 of file Uri.cs.

◆ IsAbsoluteUri

bool System.Uri.IsAbsoluteUri
get

Gets whether the T:System.Uri instance is absolute.

Returns
A T:System.Boolean value that is true if the T:System.Uri instance is absolute; otherwise, false.

Definition at line 820 of file Uri.cs.

◆ IsDefaultPort

bool System.Uri.IsDefaultPort
get

Gets whether the port value of the URI is the default for this scheme.

Returns
A T:System.Boolean value that is true if the value in the P:System.Uri.Port property is the default port for this scheme; otherwise, false.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 447 of file Uri.cs.

◆ IsFile

bool System.Uri.IsFile
get

Gets a value indicating whether the specified T:System.Uri is a file URI.

Returns
A T:System.Boolean value that is true if the T:System.Uri is a file URI; otherwise, false.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 472 of file Uri.cs.

◆ IsLoopback

bool System.Uri.IsLoopback
get

Gets whether the specified T:System.Uri references the local host.

Returns
A T:System.Boolean value that is true if this T:System.Uri references the local host; otherwise, false.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 489 of file Uri.cs.

◆ IsUnc

bool System.Uri.IsUnc
get

Gets whether the specified T:System.Uri is a universal naming convention (UNC) path.

Returns
A T:System.Boolean value that is true if the T:System.Uri is a UNC path; otherwise, false.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 570 of file Uri.cs.

◆ LocalPath

string System.Uri.LocalPath
get

Gets a local operating-system representation of a file name.

Returns
A T:System.String that contains the local operating-system representation of a file name.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 372 of file Uri.cs.

◆ OriginalString

string System.Uri.OriginalString
get

Gets the original URI string that was passed to the T:System.Uri constructor.

Returns
A T:System.String containing the exact URI specified when this instance was constructed; otherwise, F:System.String.Empty.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 739 of file Uri.cs.

◆ PathAndQuery

string System.Uri.PathAndQuery
get

Gets the P:System.Uri.AbsolutePath and P:System.Uri.Query properties separated by a question mark (?).

Returns
A T:System.String that contains the P:System.Uri.AbsolutePath and P:System.Uri.Query properties separated by a question mark (?).
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 507 of file Uri.cs.

◆ Port

int System.Uri.Port
get

Gets the port number of this URI.

Returns
An T:System.Int32 value that contains the port number for this URI.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 617 of file Uri.cs.

◆ Query

string System.Uri.Query
get

Gets any query information included in the specified URI.

Returns
A T:System.String that contains any query information included in the specified URI.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 646 of file Uri.cs.

◆ Scheme

string System.Uri.Scheme
get

Gets the scheme name for this URI.

Returns
A T:System.String that contains the scheme for this URI, converted to lowercase.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 702 of file Uri.cs.

◆ Segments

string [] System.Uri.Segments
get

Gets an array containing the path segments that make up the specified URI.

Returns
A T:System.String array that contains the path segments that make up the specified URI.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 529 of file Uri.cs.

◆ UserEscaped

bool System.Uri.UserEscaped
get

Indicates that the URI string was completely escaped before the T:System.Uri instance was created.

Returns
A T:System.Boolean value that is true if the dontEscape parameter was set to true when the T:System.Uri instance was created; otherwise, false.

Definition at line 832 of file Uri.cs.

◆ UserInfo

string System.Uri.UserInfo
get

Gets the user name, password, or other user-specific information associated with the specified URI.

Returns
A T:System.String that contains the user information associated with the URI. The returned value does not include the '@' character reserved for delimiting the user information part of the URI.
Exceptions
T:System.InvalidOperationExceptionThis instance represents a relative URI, and this property is valid only for absolute URIs.

Definition at line 845 of file Uri.cs.


The documentation for this class was generated from the following file: