Gets the original URI string that was passed to the Uri constructor.
Namespace:
System
Assembly:
System (in System.dll)
Visual Basic (Declaration)
Public ReadOnly Property OriginalString As String
Dim instance As Uri
Dim value As String
value = instance.OriginalString
public string OriginalString { get; }
public:
property String^ OriginalString {
String^ get ();
}
public function get OriginalString () : String
| Exception | Condition |
|---|
| InvalidOperationException | This instance represents a relative URI, and this property is valid only for absolute URIs. |
If the URI specified to the constructor contained leading or trailing spaces, these spaces are preserved.
The value returned by this property differs from ToString and AbsoluteUri. ToString returns the canonically unescaped form of the URI. AbsoluteUri returns the canonically escaped form of the URI.
When International Resource Identifier (IRI) and Internationalized Domain Name (IDN) support are enabled, OriginalString returns the original non normalized string with Punycode host name if one was used to initialize the Uri instance. Punycode names contain only ASCII characters and always start with the xn-- prefix.
For more information on IRI support, see the Remarks section for the Uri class.
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.
' Create a new Uri from a string address.
Dim uriAddress As New Uri("HTTP://www.ConToso.com:80//thick%20and%20thin.htm")
' Write the new Uri to the console and note the difference in the two values.
' ToString() gives the canonical version. OriginalString gives the orginal
' string that was passed to the constructor.
' The following outputs "http://www.contoso.com/thick and thin.htm".
Console.WriteLine(uriAddress.ToString())
' The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
Console.WriteLine(uriAddress.OriginalString)
End Sub 'SampleOriginalString
// Create a new Uri from a string address.
Uri uriAddress = new Uri("HTTP://www.ConToso.com:80//thick%20and%20thin.htm");
// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version. OriginalString gives the orginal
// string that was passed to the constructor.
// The following outputs "http://www.contoso.com/thick and thin.htm".
Console.WriteLine(uriAddress.ToString());
// The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
Console.WriteLine(uriAddress.OriginalString);
// Create a new Uri from a string address.
Uri^ uriAddress = gcnew Uri( "HTTP://www.ConToso.com:80//thick%20and%20thin.htm" );
// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version. OriginalString gives the orginal
// string that was passed to the constructor.
// The following outputs "http://www.contoso.com/thick and thin.htm".
Console::WriteLine( uriAddress );
// The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
Console::WriteLine( uriAddress->OriginalString );
// Create a new Uri from a string address.
Uri* uriAddress = new Uri(S"HTTP://www.ConToso.com:80//thick%20and%20thin.htm");
// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version. OriginalString gives the orginal
// string that was passed to the constructor.
// The following outputs "http://www.contoso.com/thick and thin.htm".
Console::WriteLine(uriAddress);
// The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
Console::WriteLine(uriAddress->OriginalString);
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
.NET Compact Framework
Supported in: 3.5, 2.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference