Uri.ToString Method ()


Gets a canonical string representation for the specified Uri instance.

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

    Flags = SecurityPermissionFlag.Infrastructure)>]
override ToString : unit -> string

Return Value

Type: System.String

A String instance that contains the unescaped canonical representation of the Uri instance. All characters are unescaped except #, ?, and %.

The string returned by this method does not contain port information when the port is the default port for the scheme.


The string returned by the ToString method may contain control characters, which can corrupt the state of a console application. You can use the GetComponents method with the UriFormat.SafeUnescaped format to remove control characters from the returned string.

The following example creates a new Uri instance from a string. It illustrates the difference between the value returned from OriginalString, which returns the string that was passed to the constructor, and from a call to ToString, which returns the canonical form of the string.

No code example is currently available or this language may not be supported.


to prevent partially trusted code from deriving from Uri. Associated enumeration: Infrastructure.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top