This documentation is archived and is not being maintained.

WebClient.QueryString Property

Gets or sets a collection of query name/value pairs associated with the request.

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

public function get QueryString () : NameValueCollection 
public function set QueryString (value : NameValueCollection)

Property Value

Type: System.Collections.Specialized.NameValueCollection
A NameValueCollection that contains query name/value pairs associated with the request. If no pairs are associated with the request, the value is an empty NameValueCollection.

The QueryString property contains a NameValueCollection instance containing name/value pairs that are appended to the URI as a query string. The contents of the QueryString property are preceded by a question mark (?), and name/value pairs are separated from one another by an ampersand (&).

The following code example takes user input from the command line and builds a NameValueCollection that is assigned to the QueryString property. It then downloads the response from the server to a local file.

No code example is currently available or this language may not be supported.
String* uriString = S"";
// Create a new WebClient instance.
WebClient* myWebClient = new WebClient();
// Create a new NameValueCollection instance to hold the QueryString parameters and values.
NameValueCollection* myQueryStringCollection =
   new NameValueCollection();
Console::Write(S"Enter the word(s), separated by space character to search for in {0}: ", uriString);
// Read user input phrase to search for at uriString.
String* searchPhrase = Console::ReadLine();
if (searchPhrase->Length > 1)
   // Assign the user-defined search phrase.
   myQueryStringCollection->Add(S"q", searchPhrase);
   // If error, default to search for 'Microsoft'.
   myQueryStringCollection->Add(S"q", S"Microsoft");
// Assign auxilliary parameters required for the search.
Console::WriteLine(S"Searching {0} .......", uriString);
// Attach QueryString to the WebClient.
myWebClient->QueryString = myQueryStringCollection;
// Download the search results Web page into 'searchresult.htm' for inspection.
myWebClient->DownloadFile (uriString, S"searchresult.htm");
Console::WriteLine(S"\nDownload of {0} was successful. Please see 'searchresult.htm' for results.", uriString);

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

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, 1.1, 1.0