System.Uri Class

Assembly: System.dll
Namespace: System
Summary
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.
C# Syntax:
[Serializable]
public class Uri : MarshalByRefObject, ISerializable
Remarks
A URI is a compact representation of a resource available to your application on the Internet. The Uri class defines the properties and methods for handling URIs, including parsing, comparing, and combining. The Uri class properties are read-only, to modify a Uri instance use the UriBuilder class.

The Uri class stores only absolute URIs (for example, "http://www.contoso.com/index.htm"). Relative URIs (for example, "/new/index.htm") must be expanded with respect to a base URI so that they are absolute. The Uri.MakeRelative method is provided to convert absolute URIs to relative URIs when necessary.

The Uri constructors will not escape URI strings if the string is a well-formed URI including a scheme identifier that contains escape sequences. The constructors will escape relative URI strings that contain a percent sign (%).

URIs are stored as canonical URIs in escaped encoding, with all characters with ASCII values greater than 127 replaced with their hexidecimal equivalents. To put the URI in canonical form, the Uri constructor performs the following steps.

You can transform the contents of the Uri class from an escape encoded URI reference to a readable URI reference using the Uri.ToString method.

Some URIs include a fragment identifier or query. A fragment identifier is any text that follows a number sign (#) in the URI and is stored in the Uri.Fragment property. Query information is any text that follows a question mark (?) in the URI, and is stored in the Uri.Query property.

Example
The following example creates an instance of the Uri class and uses it to create a WebRequest.
Uri siteUri = new Uri("http://www.contoso.com/");
 
 WebRequest wr = WebRequest.Create(siteUri);


    
See also:
System Namespace | UriBuilder

System.Uri Member List:

Public Constructors
ctor #1 Overloaded:
.ctor(string uriString)

Initializes a new instance of the Uri class with the specified URI.
ctor #3 Overloaded:
.ctor(string uriString, bool dontEscape)

Initializes a new instance of the Uri class with the specified URI, with control of character escaping.
ctor #4 Overloaded:
.ctor(Uri baseUri, string relativeUri)

Initializes a new instance of the Uri class based on the specified base and relative URIs.
ctor #5 Overloaded:
.ctor(Uri baseUri, string relativeUri, bool dontEscape)

Initializes a new instance of the Uri class based on the specified base and releative URIs, with control of character escaping.
Public Fields
SchemeDelimiter Specifies the characters that separate the communication protocol scheme from the address portion of the URI. This field is read-only.
UriSchemeFile Specifies that the URI is a pointer to a file. This field is read-only.
UriSchemeFtp Specifies that the URI is accessed through the File Transfer Protocol (FTP). This field is read-only.
UriSchemeGopher Specifies that the URI is accessed through the Gopher protocol. This field is read-only.
UriSchemeHttp Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). This field is read-only.
UriSchemeHttps Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS). This field is read-only.
UriSchemeMailto Specifies that the URI is an email address and is accessed through the Simple Network Mail Protocol (SNMP). This field is read-only.
UriSchemeNews Specifes that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.
UriSchemeNntp Specifes that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.
Public Properties
AbsolutePath Read-only

Gets the absolute path of the URI.
AbsoluteUri Read-only

Gets the absolute URI.
Authority Read-only

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

Gets the escaped fragment.
Host Read-only

Gets the Domain Name System (DNS) host name, or IP address of the server specified in the URI.
HostNameType Read-only

Returns the type of the host name specified in the URI.
IsDefaultPort Read-only

Gets a value indicating whether the port value of the URI is the default for this scheme.
IsFile Read-only

Gets a value indicating whether the specified Uri is a file URI.
IsLoopback Read-only

Gets a value indicating whether the specified Uri references the local host.
IsUnc Read-only

Gets a value indicating whether the specified Uri is a universal naming convention (UNC) path.
LocalPath Read-only

Gets a local operating-system representation of a file name.
PathAndQuery Read-only

Gets the Uri.AbsolutePath and Uri.Query properties separated by a question mark (?).
Port Read-only

Gets the port number of the specified URI.
Query Read-only

Gets any query information included in the specified URI.
Scheme Read-only

Gets the scheme name of the specified URI.
Segments Read-only

Gets an array of the segments that make up the specified URI.
UserEscaped Read-only

Indicates that the URI string was escaped before the Uri instance was created.
UserInfo Read-only

Gets the user name, password, and other user-specific information associated with the specified URI.
Public Methods
CheckHostName Determines whether the specified host name is valid.
CheckSchemeName Determines whether the specified scheme name is valid.
CreateObjRef
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.CreateObjRef


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
Equals Overridden:
Compares two Uri instances for equality.
FromHex Returns the decimal value of a hexadecimal digit.
GetHashCode Overridden:
Returns the hash code for the specified URI.
GetLeftPart Returns the specified portion of a URI.
GetLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.GetLifetimeService


Retrieves the current lifetime service object that controls the lifetime policy for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
HexEscape Converts a specified character into its hexadecimal equivalent.
HexUnescape Converts a specified hexadecimal representation of a character to the character.
InitializeLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.InitializeLifetimeService


Obtains a lifetime service object to control the lifetime policy for this instance.
IsHexDigit Determines whether a specified character is a valid hexadecimal digit.
IsHexEncoding Determines whether a string is hexadecimal encoded.
MakeRelative Determines the difference between two Uri instances.
ToString Overridden:
Returns the display string for the specified Uri instance.
Protected Constructors
ctor #2 Overloaded:
.ctor(SerializationInfo serializationInfo, StreamingContext streamingContext)

Initializes a new instance of the Uri class from the specified instances of the SerializationInfo and StreamingContext classes.
Protected Methods
Canonicalize
CheckSecurity
Escape
EscapeString Converts a string to its escaped representation.
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
IsBadFileSystemCharacter
IsExcludedCharacter
IsReservedCharacter
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.
Parse
Unescape

Hierarchy:


System.Uri Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the Uri class with the specified URI.
C# Syntax:
public Uri(
   string uriString
);
Parameters:

uriString

A URI.

Exceptions
Exception Type Condition
UriFormatException uriString is empty.

-or-

The scheme specified in uriString is invalid.

-or-

uriString contains too many slashes.

-or-

The password specified in uriString is invalid.

-or-

The host name specified in uriString is invalid.

-or-

The file name specified in uriString is invalid.

Remarks
This constructor creates a Uri instance from a URI string. It parses the URI, puts it in canonical format, and makes any required escape encodings.
Example
The following example creates a Uri instance with the URI "http://www.contoso.com/".
Uri myUri = new Uri("http://www.contoso.com/");


    

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the Uri class from the specified instances of the SerializationInfo and StreamingContext classes.
C# Syntax:
protected Uri(
   SerializationInfo serializationInfo,
   StreamingContext streamingContext
);
Parameters:

serializationInfo

An instance of the SerializationInfo class containing the information required to serialize the new Uri instance.

streamingContext

An instance of the StreamingContext class containing the source of the serialized stream associated with the new Uri instance.

Remarks
This constructor implements the ISerializable interface for the Uri class.
See also:
MSDN: serialization

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the Uri class with the specified URI, with control of character escaping.
C# Syntax:
public Uri(
   string uriString,
   bool dontEscape
);
Parameters:

uriString

The URI.

dontEscape

true if the URI contains escape characters; otherwise, false.

Exceptions
Exception Type Condition
ArgumentException uriString is empty.

-or-

uriString is null.

UriFormatException The scheme specified in uriString is invalid.

-or-

uriString contains too many slashes.

-or-

The password specified in uriString is invalid.

-or-

The host name specified in uriString is invalid.

-or-

The file name specified in uriString is invalid.

Remarks
This constructor creates a Uri instance from a URI string. It parses the URI, and puts it in canonical format. The caller must set dontEscape to true if the URI is already escaped, or false if the constructor should transform the URI to its escaped encoding.
Example
The following example creates a Uri instance for the URI http://www.contoso.com/Hello%20World.htm. Because the URI contains escaped characters, the third parameter, dontEscape, is set to true.
Uri myUri = new Uri("http://www.contoso.com/Hello%20World.htm", true);


    

Return to top


Overloaded ctor #4
Summary
Initializes a new instance of the Uri class based on the specified base and relative URIs.
C# Syntax:
public Uri(Uri baseUri, string relativeUri(
   Uri baseUri,
   string relativeUri
);
Parameters:

baseUri

The base URI.

relativeUri

The relative URI to add to the base URI.

Exceptions
Exception Type Condition
UriFormatException The URI formed by combining baseUri and relativeUri is empty.

-or-

The scheme specified in the URI formed by combining baseUri and relativeUri is invalid.

-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 invalid.

-or-

The host name specified in the URI formed by combining baseUri and relativeUri is invalid.

-or-

The file name specified in the URI formed by combining baseUri and relativeUri is invalid.

Remarks
This constructor creates a Uri instance by combining the baseUri and the relativeUri. If relativeUri is an absolute URI (containing a scheme, hostname, and optionally a port number) the Uri instance is created using only relativeUri.
Example
The following example creates a new instance of the Uri class by combining the relative URIs http://www.contoso.com and catalog/showew.htm to form the absolute URI http://www.contoso.com/catalog/shownew.htm .
Uri baseUri = new Uri("http://www.contoso.com");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm");

Console.WriteLine(myUri.ToString());
   

    

Return to top


Overloaded ctor #5
Summary
Initializes a new instance of the Uri class based on the specified base and releative URIs, with control of character escaping.
C# Syntax:
public Uri(Uri baseUri, string relativeUri(
   Uri baseUri,
   string relativeUri,
   bool dontEscape
);
Parameters:

baseUri

The base URI.

relativeUri

The relative URI to add to the base URI.

dontEscape

true if the URI contains escape characters; otherwise, false.

Exceptions
Exception Type Condition
UriFormatException The URI formed by combining baseUri and relativeUri is empty.

-or-

The scheme specified in the URI formed by combining baseUri and relativeUri is invalid.

-or-

Ehe 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 invalid.

-or-

The host name specified in the URI formed by combining baseUri and relativeUri is invalid.

-or-

The file name specified in the URI formed by combining baseUri and relativeUri is invalid.

Remarks
This constructor creates a Uri instance by combining baseUri and relativeUri. If the URI passed in relativeUri is an absolute URI (containing a scheme, hostname, and optionally a port number) the Uri instance is created using only relativeUri. The caller must set dontEscape to true if the URI is already escaped.
Example
The following example creates a new instance of the Uri class by combining the relative URIs http://www.contoso.com and Hello%20World.htm to form an absolute URI. Because the URI contains escaped characters, the third parameter, dontEscape, is set to true.
Uri baseUri = new Uri("http://www.contoso.com");
 Uri myUri = new Uri(baseUri, "Hello%20World.htm",true);
   

    

Return to top


Field: SchemeDelimiter
Summary
Specifies the characters that separate the communication protocol scheme from the address portion of the URI. This field is read-only.
C# Syntax:
public static readonly string SchemeDelimiter;

Return to top


Field: UriSchemeFile
Summary
Specifies that the URI is a pointer to a file. This field is read-only.
C# Syntax:
public static readonly string UriSchemeFile;

Return to top


Field: UriSchemeFtp
Summary
Specifies that the URI is accessed through the File Transfer Protocol (FTP). This field is read-only.
C# Syntax:
public static readonly string UriSchemeFtp;

Return to top


Field: UriSchemeGopher
Summary
Specifies that the URI is accessed through the Gopher protocol. This field is read-only.
C# Syntax:
public static readonly string UriSchemeGopher;

Return to top


Field: UriSchemeHttp
Summary
Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). This field is read-only.
C# Syntax:
public static readonly string UriSchemeHttp;

Return to top


Field: UriSchemeHttps
Summary
Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS). This field is read-only.
C# Syntax:
public static readonly string UriSchemeHttps;

Return to top


Field: UriSchemeMailto
Summary
Specifies that the URI is an email address and is accessed through the Simple Network Mail Protocol (SNMP). This field is read-only.
C# Syntax:
public static readonly string UriSchemeMailto;

Return to top


Field: UriSchemeNews
Summary
Specifes that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.
C# Syntax:
public static readonly string UriSchemeNews;

Return to top


Field: UriSchemeNntp
Summary
Specifes that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.
C# Syntax:
public static readonly string UriSchemeNntp;

Return to top


Property: AbsolutePath (read-only)
Summary
Gets the absolute path of the URI.
C# Syntax:
public string AbsolutePath {get;}
Remarks
The Uri.AbsolutePath property contains the path information that the server uses to resolve requests for information. Typically this is the path to the desired information on the server's file system, although it also can indicate the application or script the server must run to provide the information.

The path information does not include the scheme, host name, or query portion of the URI. The Uri.AbsolutePath property always returns at least a slash (/).

Example
The following example writes the path /catalog/shownew.htm to the console.
Uri baseUri = new Uri("http://www.contoso.com/");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm?date=today");
 
 Console.WriteLine(myUri.AbsolutePath);
   

    

Return to top


Property: AbsoluteUri (read-only)
Summary
Gets the absolute URI.
C# Syntax:
public string AbsoluteUri {get;}
Remarks
The Uri.AbsoluteUri property includes the entire URI stored in the Uri instance, including all fragments and query strings.
Example
The following example writes the complete contents of the Uri instance to the console. In the example shown, http://www.contoso.com/catalog/shownew.htm?date=today is written to the console:
Uri baseUri= new Uri("http://www.contoso.com");
 Uri myUri = new Uri(baseUri,"catalog/shownew.htm?date=today");
 Console.WriteLine(myUri.AbsoluteUri);
   

    

Return to top


Property: Authority (read-only)
Summary
Gets the Domain Name System (DNS) host name or IP address and the port number for a server.
C# Syntax:
public string Authority {get;}
Remarks
The Authority property returns the fully qualified DNS host name or IP address of the server specified in the URI, along with the port number for nondefault ports.
Example
The following example writes the host name (www.contoso.com ) and port number (8080) of the server to the console.
 Uri baseUri = new Uri("http://www.contoso.com:8080/");
 Uri myUri = new Uri(baseUri,"shownew.htm?date=today");
 
 Console.WriteLine(myUri.Authority);
   

    

Return to top


Property: Fragment (read-only)
Summary
Gets the escaped fragment.
C# Syntax:
public string Fragment {get;}
Remarks
The Uri.Fragment property gets any text following a fragment marker (#) in the URI, including the fragment marker itself. Given the URI http://www.contoso.com/index.htm#main , the fragment property would get #main.

The Uri.Fragment property is not considered in any Uri.Equals comparison.

Return to top


Property: Host (read-only)
Summary
Gets the Domain Name System (DNS) host name, or IP address of the server specified in the URI.
C# Syntax:
public string Host {get;}
Remarks
The Uri.Host property gets the fully qualified DNS host name or IP address of the server specified in the URI.
Example
The following example writes the host name (www.contoso.com ) of the server to the console.
Uri baseUri = new Uri("http://www.contoso.com:8080/");
Uri myUri = new Uri(baseUri, "shownew.htm?date=today");
 
 Console.WriteLine(myUri.Host);
   

    

Return to top


Property: HostNameType (read-only)
Summary
Returns the type of the host name specified in the URI.
C# Syntax:
public UriHostNameType HostNameType {get;}

Return to top


Property: IsDefaultPort (read-only)
Summary
Gets a value indicating whether the port value of the URI is the default for this scheme.
C# Syntax:
public bool IsDefaultPort {get;}

Return to top


Property: IsFile (read-only)
Summary
Gets a value indicating whether the specified Uri is a file URI.
C# Syntax:
public bool IsFile {get;}
Remarks
The Uri.IsFile property is true when the Uri.Scheme property equals Uri.UriSchemeFile.

Return to top


Property: IsLoopback (read-only)
Summary
Gets a value indicating whether the specified Uri references the local host.
C# Syntax:
public bool IsLoopback {get;}
Remarks
IsLoopback returns true if the specified Uri address is either 127.0.0.1, loopback, or localhost. All other addresses return false.

Return to top


Property: IsUnc (read-only)
Summary
Gets a value indicating whether the specified Uri is a universal naming convention (UNC) path.
C# Syntax:
public bool IsUnc {get;}
Remarks
The Uri.IsUnc property is true if the specified Uri instance is a UNC path (suc as \\server\folder ).

Return to top


Property: LocalPath (read-only)
Summary
Gets a local operating-system representation of a file name.
C# Syntax:
public string LocalPath {get;}

Return to top


Property: PathAndQuery (read-only)
Summary
Gets the Uri.AbsolutePath and Uri.Query properties separated by a question mark (?).
C# Syntax:
public string PathAndQuery {get;}
Remarks
The Uri.PathAndQuery property contains the absolute path on the server and the query information sent with the request. It is identical to concatenating the Uri.AbsolutePath and Uri.Query properties.

The Uri.PathAndQuery property is escaped according to RFC 2396.

Example
The following example writes the URI's path (/catalog/shownew.htm) and query (date= today) information to the console.
Uri baseUri = new Uri("http://www.contoso.com/");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm?date=today");
 
 Console.WriteLine(myUri.PathAndQuery);
   

    

Return to top


Property: Port (read-only)
Summary
Gets the port number of the specified URI.
C# Syntax:
public int Port {get;}
Remarks
The port number defines the protocol port used for contacting the server referenced in the URI. If a port is not is not specified as part of the URI, the Uri.Port property returns the default value for the protocol.
Example
The following example writes the URI's port number to the console. In this case, the value is the default port number for HTTP, port 80.
Uri baseUri = new Uri("http://www.contoso.com/");
 Uri myUri = new Uri(baseUri,"catalog/shownew.htm?date=today");
 
 Console.WriteLine(myUri.Port);
   

    

Return to top


Property: Query (read-only)
Summary
Gets any query information included in the specified URI.
C# Syntax:
public string Query {get;}
Remarks
The Uri.Query property contains any query information included in the URI. Query information is separated from the path information by a question mark (?) and continues to the end of the URI. The query information returned includes the leading question mark.

The query information is escaped according to RFC 2396.

Example
The following example writes the query ?date= today to the console.
Uri baseUri = new Uri("http://www.contoso.com/");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm?date=today");
 
 Console.WriteLine(myUri.Query);
   
	. . . 
Uri baseUri = new Uri("http://www.contoso.com/");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm?date=today");
 
 Console.WriteLine(myUri.Query);
   

    

Return to top


Property: Scheme (read-only)
Summary
Gets the scheme name of the specified URI.
C# Syntax:
public string Scheme {get;}
Remarks
The following table lists the valid scheme names for the Uri.Scheme property.

Scheme Description
file The resource is a file on the local computer.
ftp The resource is through FTP.
gopher The resource is accessed through the Gopher protocol.
http The resource is accessed through HTTP.
https The resource is accessed through secure HTTP.
mailto The resource is an e-mail address and accessed through SMTP.
news The resources is accessed through NNTP.
Example
The following example writes the scheme name (http) to the console for the URI http://www.contoso.com/ .
Uri baseUri = new Uri("http://www.contoso.com/");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm?date=today");
 
 Console.WriteLine(myUri.Scheme);
   

    

Return to top


Property: Segments (read-only)
Summary
Gets an array of the segments that make up the specified URI.
C# Syntax:
public string[] Segments {get;}

Return to top


Property: UserEscaped (read-only)
Summary
Indicates that the URI string was escaped before the Uri instance was created.
C# Syntax:
public bool UserEscaped {get;}
Remarks
The Uri.UserEscaped property is set to true to indicate that the string used to create the Uri instance was escaped before it was passed to the constructor; that is, the dontEscape parameter of the constructor call was set to true.
Example
The following example writes the value (true) of the Uri.UserEscaped property to the console.
Uri myUri = new Uri("http://www.contoso.com/thick%20and%20thin.htm",true);

 Console.WriteLine(myUri.UserEscaped);
   

    

Return to top


Property: UserInfo (read-only)
Summary
Gets the user name, password, and other user-specific information associated with the specified URI.
C# Syntax:
public string UserInfo {get;}

Return to top


Method: Canonicalize()
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected virtual void Canonicalize();

Return to top


Method: CheckHostName(
   string name
)
Summary
Determines whether the specified host name is valid.
C# Syntax:
public static UriHostNameType CheckHostName(
   string name
);
Parameters:

name

The host name to validate.

Return Value:
true if the host name is valid; otherwise, false.
Remarks
The Uri.CheckHostName method checks that the host name provided meets the requirements for a valid Internet host name. It does not, however, perform a host-name lookup to verify the existence of the host.
Example
The following example checks the host name is checked for validity.
Console.WriteLine(Uri.CheckHostName("www.contoso.com"));
   

    

Return to top


Method: CheckSchemeName(
   string schemeName
)
Summary
Determines whether the specified scheme name is valid.
C# Syntax:
public static bool CheckSchemeName(
   string schemeName
);
Parameters:

schemeName

The scheme name to validate.

Return Value:
true if the scheme name is valid; otherwise, false.
Remarks
The CheckSchemeName method checks the scheme name for validity according to RFC 2396. The scheme name must begin with a letter, and must contain only letters, digits, and the characters ".", "+", or "-".

Return to top


Method: CheckSecurity()
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected virtual void CheckSecurity();

Return to top


Method: CreateObjRef(
   Type requestedType
)
Inherited
See base class member description: System.MarshalByRefObject.CreateObjRef

Summary
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
C# Syntax:
public virtual ObjRef CreateObjRef(
   Type requestedType
);
Parameters:

requestedType

The Type of the object that the new ObjRef will reference.

Return Value:
Information required to generate a proxy.
Exceptions
Exception Type Condition
RemotingException This instance is not a valid remoting object.

Return to top


Overridden Method: Equals(
   object comparand
)
Summary
Compares two Uri instances for equality.
C# Syntax:
public override bool Equals(
   object comparand
);
Parameters:

comparand

The Uri instance to compare with the current instance.

Return Value:
true if the two Uri instances contain the same URI; otherwise, false.
Remarks
The Uri.Equals method compares two URI instances without regard to any fragments that they might contain. For instance, given the URIs http://www.contoso.com/index.htm#search and http://www.contoso.com/index.htm the Uri.Equals method would return true.

Return to top


Method: Escape()
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected virtual void Escape();

Return to top


Method: EscapeString(
   string str
)
Summary
Converts a string to its escaped representation.
C# Syntax:
protected static string EscapeString(
   string str
);
Parameters:

str

The string to transform to its escaped representation.

Return Value:
The escaped representation of the string.
Remarks
The Uri.EscapeString method converts all characters with an ASCII value greater than 127 to hexidecimal representation.

The string is escaped according to RFC 2396.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Uri();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: FromHex(
   char digit
)
Summary
Returns the decimal value of a hexadecimal digit.
C# Syntax:
public static int FromHex(
   char digit
);
Parameters:

digit

The hexadecimal digit (0-9, a-f, A-F) to convert.

Return Value:
A number from 1 - 15 that corresponds to the specified hexadecimal digit.
Exceptions
Exception Type Condition
ArgumentException digit is not a valid hexadecimal digit (0-9, a-f, A-F).
Remarks
The Uri.FromHex method converts a character representing a hexadecimal digit (0-9, a-f, A-F) to its decimal value (0-15). If digit is not a valid hexadecimal digit, ArgumentException is thrown.

Return to top


Overridden Method: GetHashCode()
Summary
Returns the hash code for the specified URI.
C# Syntax:
public override int GetHashCode();
Return Value:
The hash value generated for the URI.
Remarks
The Uri.GetHashCode method generates the URI's hash value without including any fragment identifiers. For example, the URIs http://www.contoso.com/index.htm#search and http://www.contoso.com/index.htm yield the same hash code.

Return to top


Method: GetLeftPart(
   UriPartial part
)
Summary
Returns the specified portion of a URI.
C# Syntax:
public string GetLeftPart(
   UriPartial part
);
Parameters:

part

One of the UriPartial values that specifies the the end of the portion of the URI to return.

Return Value:
A string containing the specified portion of the URI.
Remarks
The Uri.GetLeftPart method returns a string containing the left-most portion of the URI, ending with the portion specified by part. The string returned includes delimiters but does not include any fragments or queries or their delimiters, except in certain cases.

Uri.GetLeftPart includes delimiters in the following cases:

The following examples show a URI and the results of calling Uri.GetLeftPart with UriPartial.Scheme, UriPartial.Authority, or UriPartial.Path.



URI Scheme Authority Path
http://www.contoso.com/index.htm#main http:// http://www.contoso.com http://www.contoso.com/
mailto:user@contoso.com?subject=uri mailto: mailto:user@contoso.com
nntp://news.contoso.com/123456@contoso.com nntp:// nntp://news.contoso.com nntp://news.contoso.com/123456@contoso.com
news:123456@contoso.com news: news:123456@contoso.com
file://server/filename.ext file:// file://server file://server/filename.ext
file:/filename.ext file: file:/filename.ext

Return to top


Method: GetLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.GetLifetimeService

Summary
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
C# Syntax:
public object GetLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance.
Remarks
For more information about lifetime services, see the LifetimeServices class.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: HexEscape(
   char character
)
Summary
Converts a specified character into its hexadecimal equivalent.
C# Syntax:
public static string HexEscape(
   char character
);
Parameters:

character

The character to convert to hexadecimal representation.

Return Value:
The hexadecimal representation of the specified character.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException character is greater than 255.

Return to top


Method: HexUnescape(
   string pattern,
   ref int index
)
Summary
Converts a specified hexadecimal representation of a character to the character.
C# Syntax:
public static char HexUnescape(
   string pattern,
   ref int index
);
Parameters:

pattern

The hexadecimal representation of a character.

index

The location in pattern where the hexadecimal representation of a character begins.

Return Value:
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.

Return to top


Method: InitializeLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.InitializeLifetimeService

Summary
Obtains a lifetime service object to control the lifetime policy for this instance.
C# Syntax:
public virtual object InitializeLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.
Remarks
For more information about lifetime services, see the LifetimeServices class.
Example
The following code example demonstrates creating a lease.
 public class MyClass : MarshalByRefObject
 {
   public override Object InitializeLifetimeService()
   {
     ILease lease = (ILease)base.InitializeLifetimeService();
     if (lease.CurrentState == LeaseState.Initial)
     {
          lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
          lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
           lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
     }
       return lease;
   }
 }

    

Return to top


Method: IsBadFileSystemCharacter(
   char character
)
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected virtual bool IsBadFileSystemCharacter(
   char character
);
Parameters:

character

Return to top


Method: IsExcludedCharacter(
   char character
)
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected static bool IsExcludedCharacter(
   char character
);
Parameters:

character

Return to top


Method: IsHexDigit(
   char character
)
Summary
Determines whether a specified character is a valid hexadecimal digit.
C# Syntax:
public static bool IsHexDigit(
   char character
);
Parameters:

character

The character to validate.

Return Value:
true if the character is a valid hexadecimal digit; otherwise false.
Remarks
Hexadecimal digits are the digits 0-9 and the letters A-F or a-f.

Return to top


Method: IsHexEncoding(
   string pattern,
   int index
)
Summary
Determines whether a string is hexadecimal encoded.
C# Syntax:
public static bool IsHexEncoding(
   string pattern,
   int index
);
Parameters:

pattern

The string to check.

index

The location in pattern to check for hexadecimal encoding.

Return Value:
true if pattern is hexadecimal encoded at the specified location; otherwise, false.
Remarks
The Uri.IsHexEncoding method checks for hexadecimal encoding that follows the pattern "%hexhex" in a string, where "hex" is a digit from 0-9 or or a letter from A-F (case-insensitive).

Return to top


Method: IsReservedCharacter(
   char character
)
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected virtual bool IsReservedCharacter(
   char character
);
Parameters:

character

Return to top


Method: MakeRelative(
   Uri toUri
)
Summary
Determines the difference between two Uri instances.
C# Syntax:
public string MakeRelative(
   Uri toUri
);
Parameters:

toUri

The URI to compare to the current URI.

Return Value:
If the two URIs are the same except for the path information, then that difference; if the two have additional differences, the absolute URI of toUri.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Parse()
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected virtual void Parse();

Return to top


Overridden Method: ToString()
Summary
Returns the display string for the specified Uri instance.
C# Syntax:
public override string ToString();
Return Value:
The string containing the unescaped display name of the Uri.

Return to top


Method: Unescape(
   string path
)
Summary
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
protected virtual string Unescape(
   string path
);
Parameters:

path

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.