Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
Uri Class
Uri Constructor
 Uri Constructor (String, Boolean)
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Uri Constructor (String, Boolean)

Updated: November 2007

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)

Visual Basic (Declaration)
<ObsoleteAttribute("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")> _
Public Sub New ( _
    uriString As String, _
    dontEscape As Boolean _
)
Visual Basic (Usage)
Dim uriString As String
Dim dontEscape As Boolean

Dim instance As New Uri(uriString, _
    dontEscape)
C#
[ObsoleteAttribute("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]
public Uri(
    string uriString,
    bool dontEscape
)
Visual C++
[ObsoleteAttribute(L"The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]
public:
Uri(
    String^ uriString, 
    bool dontEscape
)
J#
/** @attribute ObsoleteAttribute("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202") */
public Uri(
    String uriString,
    boolean dontEscape
)
JScript
public function Uri(
    uriString : String, 
    dontEscape : boolean
)

Parameters

uriString
Type: System..::.String

The URI.

dontEscape
Type: System..::.Boolean

true if uriString is completely escaped; otherwise, false. See Remarks.

ExceptionCondition
ArgumentNullException

uriString is nullNothingnullptra null reference (Nothing in Visual Basic).

UriFormatException

uriString 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 65534 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:\\.

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 http://www.contoso.com/Hello%20World.htm. Because the contained URI is completely escaped and is in canonical form, the dontEscape parameter can be set to true.

Visual Basic
Dim myUri As New Uri("http://www.contoso.com/Hello%20World.htm", True)


C#
Uri myUri = new Uri("http://www.contoso.com/Hello%20World.htm", true);


Visual C++
Uri^ myUri = gcnew Uri(  "http://www.contoso.com/Hello%20World.htm",true );

J#
Uri myUri = new Uri("http://www.contoso.com/Hello%20World.htm", true);

JScript
    var myUri : Uri = new Uri("http://www.contoso.com/Hello%20World.htm", true);

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

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

.NET Framework

Supported in: 1.1, 1.0
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 2.0
Obsolete (compiler warning) in 2.0 SP1

.NET Compact Framework

Supported in: 1.0
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 2.0

XNA Framework

Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker