TechNet
Export (0) Print
Expand All

Uri.Query Property

 

Gets any query information included in the specified URI.

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

public string Query { get; }

Property Value

Type: System.String

A String that contains any query information included in the specified URI.

Exception Condition
InvalidOperationException

This instance represents a relative URI, and this property is valid only for absolute URIs.

The Query property contains any query information included in the URI. Query information is separated from the path information by a question mark (?) and continues to the end of the URI. The query information returned includes the leading question mark.

The query information is escaped according to RFC 2396 by default. If International Resource Identifiers (IRIs) or Internationalized Domain Name (IDN) parsing is enabled, the query information is escaped according to RFC 3986 and RFC 3987.

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

The following example writes the query ?date= today to the console.

Uri baseUri = new Uri ("http://www.contoso.com/");
Uri myUri = new Uri (baseUri, "catalog/shownew.htm?date=today");

Console.WriteLine (myUri.Query);

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
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:
© 2016 Microsoft