Uri.IsWellFormedUriString Method

July 28, 2014

Indicates whether the string is well-formed by attempting to construct a Uri with the string and ensures that the string does not require further escaping.

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

public static bool IsWellFormedUriString(
	string uriString,
	UriKind uriKind
)

Parameters

uriString
Type: System.String
A Uri represented as a string.
uriKind
Type: System.UriKind
The type of the URI in uriString parameter.

Return Value

Type: System.Boolean
A Boolean value that is true if the string was well-formed in accordance with RFC 3986; else false.

The string is considered poorly formed, causing the method to return false, if any of the following conditions occur

Error

Example

The string is not correctly escaped.

http://www.contoso.com/path???/file name

The string is an absolute Uri that represents an implicit file Uri.

c:\\directory\filename

The string is an absolute URI that is missing a slash before the path.

file://c:/directory/filename

The string contains unescaped backslashes even if they will be treated as forward slashes

http:\\host/path/file

The string represents a hierarchical absolute Uri and does not contain "://"

www.contoso.com/path/file

The parser for the Scheme indicates that the original string was not well-formed.

The example depends on the scheme of the URI.

For more information, see RFC 2396, RFC 2732, and RFC 3986 available at http://www.ietf.org.

A 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 the string is passed to one of the constructors for Uri.

The Uri constructors allow a Windows Phone application to create a Uri instance for many schemes as described in the Scheme property. However, only Uri instances for the UriSchemeHttp or UriSchemeHttps schemes are supported by the WebClient and HTTP classes in the System.Net namespace.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft