Constructs and initializes a new instance of the Uri class by parsing the specified URI.
- uriString
- A string containing a URI.
- dontEscape
- true if the URI in uriString is already escaped; otherwise, false.
Type Reason ArgumentNullException uriString is null . UriFormatException uriString is a zero length string or contains only spaces.
-or-
The parsing routine detected a scheme in an invalid form.
-or-
The parser detected more than two consecutive slashes in a URI that does not use the "file" scheme.
-or-
uriString is in an invalid form and cannot be parsed.
This constructor parses the URI, places its components into the appropriate properties, and puts the URI in canonical form. If the specified URI does not contain a scheme component, the URI is parsed using "file" as the scheme.
The following example creates a Uri instance for the URI "http://www.contoso.com/Hello%20World.htm". Because the URI contains escaped characters, the third parameter, dontEscape , is set to true .
C# Example
using System; public class UriTest { public static void Main() { Uri myUri = new Uri("http://www.contoso.com/Hello%20World.htm", true); Console.WriteLine(myUri.ToString()); } }The output is
http://www.contoso.com/Hello World.htm
Namespace: System
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0