Uri Constructor (String, UriKind)
Collapse the table of content
Expand the table of content

Uri Constructor (String, UriKind)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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)

public Uri(
	string uriString,
	UriKind uriKind


Type: System.String
A string that identifies the resource to be represented by the Uri instance.
Type: System.UriKind
Specifies whether the URI string is a relative URI, absolute URI, or is indeterminate.


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


uriString is null.


uriString contains a relative URI and uriKind is Absolute.


uriString contains an absolute URI and uriKind is Relative.

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 Windows Phone 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.

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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft