Uri Constructor (String, UriKind)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Sub New ( _
    uriString As String, _
    uriKind As UriKind _
)
public Uri(
    string uriString,
    UriKind uriKind
)

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.

Exceptions

Exception Condition
ArgumentException

uriKind is not valid (possible values are Absolute, Relative, or RelativeOrAbsolute).

ArgumentNullException

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

UriFormatException

uriString contains a relative URI and uriKind is Absolute.

or

uriString contains an absolute URI and uriKind is Relative.

Remarks

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.

The uriString can be poorly formed and can still be used to construct a Uri instance. The Silverlight runtime will try to correct some minor issues with a poorly-formed string when this constructor is called to create a Uri instance.

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

Silverlight-based applications are cross-platform, so they run in most modern Web browsers, including Apple Safari version 2.0 and later on Apple Mac OS X. However, Uri(String, UriKind) does not convert backslashes in the uriString parameter to forward slashes in the Uri on Apple Mac OS X.

Examples

Dim myUri As New Uri("https://www.contoso.com/Hello%20World.htm", UriKind.Absolute)
Uri myUri = new Uri("https://www.contoso.com/Hello%20World.htm", UriKind.Absolute);

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.