Gets or sets a collection of query name/value pairs associated with the request.
Assembly: System (in System.dll)
Property ValueType: System.Collections.Specialized.NameValueCollection
The NameValueCollection instance containing name/value pairs that are appended to the URI as a query string. The contents of the property are preceded by a question mark (?), and name/value pairs are separated from one another by an ampersand (&).property contains a
The following code example takes user input from the command line and builds a NameValueCollection that is assigned to the property. It then downloads the response from the server to a local file.
Dim uriString As String = "http://www.contoso.com/search" ' Create a new WebClient instance. Dim myWebClient As New WebClient() ' Create a new NameValueCollection instance to hold the QueryString parameters and values. Dim myQueryStringCollection As New NameValueCollection() Console.Write(("Enter the word(s), separated by space characters, to search for in " + uriString + ": ")) ' Read user input phrase to search in uriString. Dim searchPhrase As String = Console.ReadLine() If searchPhrase.Length > 1 Then 'Assign the user-defined search phrase. myQueryStringCollection.Add("q", searchPhrase) ' If error, default to search 'Microsoft'. Else myQueryStringCollection.Add("q", "Microsoft") End If ' Assign auxilliary parameters required for the search. Console.WriteLine(("Searching " + uriString + " .......")) ' Attach QueryString to the WebClient. myWebClient.QueryString = myQueryStringCollection ' Download the search results Web page into 'searchresult.htm' for inspection. myWebClient.DownloadFile(uriString, "searchresult.htm") Console.WriteLine((ControlChars.Cr + "Download of " + uriString + " was successful. Please see 'searchresult.htm' for results."))
Available since 1.1