This documentation is archived and is not being maintained.

Uri Constructor (String, Boolean)

Note: This API is now obsolete.

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

Namespace:  System
Assembly:  System (in System.dll)

[ObsoleteAttribute("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false.")]
public Uri(
	string uriString,
	bool dontEscape


Type: System.String
The URI.
Type: System.Boolean
true if uriString is completely escaped; otherwise, false. See Remarks.


uriString is null.


uriString is empty or contains only spaces.


The scheme specified in uriString is not valid.


uriString contains too many slashes.


The password specified in uriString is not valid.


The host name specified in uriString is not valid.


The file name specified in uriString is not valid.


The user name specified in uriString is not valid.


The host or authority name specified in uriString cannot be terminated by backslashes.


The port number specified in uriString is not valid or cannot be parsed.


The length of uriString exceeds 65519 characters.


The length of the scheme specified in uriString exceeds 1023 characters.


There is an invalid character sequence in uriString.


The MS-DOS path specified in uriString must start with c:\\.

This constructor creates a Uri instance from a URI string. It parses the URI and puts it in canonical format.

The dontEscape parameter controls whether reserved characters are translated into escape sequences. This parameter should be set to true only if you are certain that all reserved characters in the URI have been escaped. Setting the value to true for a URI that has not been completely escaped can cause unexpected behavior. It is strongly recommended that you always set this parameter to false.

If dontEscape is set to false, the constructor escapes any reserved characters by checking that all occurrences of percent (%) are followed by a valid escape sequence. If the character sequence following a percent is not valid, the percent is replaced by %25.

This constructor does not ensure that the Uri refers to an accessible resource.

The following example creates a Uri instance for the URI Because the contained URI is completely escaped and is in canonical form, the dontEscape parameter can be set to true.

Uri myUri = new Uri("", true);

.NET Framework

Supported in: 1.1, 1.0
Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2

.NET Framework Client Profile

Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.