Export (0) Print
Expand All

Uri.OriginalString Property

Gets the original URI string that was passed to the Uri constructor.

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

public string OriginalString { get; }

Property Value

Type: System.String
A String containing the exact URI specified when this instance was constructed; otherwise, Empty.

ExceptionCondition
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 a Uri object is serialized, the OriginalString is not preserved. The serialization process uses the fully escaped and canonicalized AbsoluteUri property when serializing.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 The OriginalString property trims any leading space before the scheme in the URL.

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.
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".
outputBlock.Text += uriAddress.ToString();
outputBlock.Text += "\n";

// The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
outputBlock.Text += uriAddress.OriginalString;
outputBlock.Text += "\n";


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft