Uri Constructor (String, UriKind)

 

Initializes a new instance of the 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.

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

new : 
        uriString:string *
        uriKind:UriKind -> Uri

Parameters

uriString
Type: System.String

A string that identifies the resource to be represented by the Uri instance.

uriKind
Type: System.UriKind

Specifies whether the URI string is a relative URI, absolute URI, or is indeterminate.

Exception Condition
ArgumentException

uriKind is invalid.

ArgumentNullException

uriString is null.

UriFormatException
System_CAPS_noteNote

In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

uriString contains a relative URI and uriKind is Absolute.

or

uriString contains an absolute URI and uriKind is Relative.

or

uriString is empty.

-or-

The scheme specified in uriString is not correctly formed. See CheckSchemeName.

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

Relative and absolute URIs have different restrictions on their format. For example, a relative URI does not require a scheme or an authority. The value you specify in uriKind must match the type of URI passed in uriString. However, if RelativeOrAbsolute is specified, the URI string can be relative or absolute.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: