Uri.IsWellFormedUriString Method (String, UriKind)

 

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

The string used to attempt to construct a Uri.

uriKind
Type: System.UriKind

The type of the Uri in uriString.

Return Value

Type: System.Boolean

A Boolean value that is true if the string was well-formed; else false.

In versions of .NET before version 4.5, by default the string is considered well-formed in accordance with RFC 2396 and RFC 2732. If International Resource Identifiers (IRIs) or Internationalized Domain Name (IDN) parsing are enabled, the string is considered well-formed in accordance with RFC 3986 and RFC 3987.

Beginning in .NET 4.5, strings are always considered well-formed in accordance with RFC 3986 and RFC 3987, whether or not IRI or IDN are enabled. Note, however, that this is only true for apps that target .NET 4.5 or later. Apps that target .NET 4.0 invoke compatibility code, and experience the old (pre-4.5) behavior.

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.

Beginning with .NET 4.5, relative URIs with a colon (':') in their first segment are not considered well-formed.

2013.05.29_14:33:41

For more information on IRI support, see the Remarks section for the Uri class.

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: