WebClient.QueryString Property
.NET Framework 3.0
Gets or sets a collection of query name/value pairs associated with the request.
Namespace: System.Net
Assembly: System (in system.dll)
Assembly: System (in system.dll)
/** @property */ public NameValueCollection get_QueryString () /** @property */ public void set_QueryString (NameValueCollection value)
public function get QueryString () : NameValueCollection public function set QueryString (value : NameValueCollection)
Not applicable.
Property Value
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 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.
string uriString = "http://www.contoso.com/search"; // 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("Enter the word(s), separated by space character to search for in " + 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("q",searchPhrase); else // If error, default to search for 'Microsoft'. myQueryStringCollection.Add("q","Microsoft"); // 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("\nDownload of " + uriString + " was successful. Please see 'searchresult.htm' for results.");
String uriString = "http://www.contoso.com/search";
// 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("Enter the word(s), separated by space character"
+ " to search for in " + uriString + ": ");
// Read user input phrase to search for at uriString.
String searchPhrase = Console.ReadLine();
if (searchPhrase.get_Length() > 1) {
// Assign the user-defined search phrase.
myQueryStringCollection.Add("q", searchPhrase);
}
else {
// If error, default to search for 'Microsoft'.
myQueryStringCollection.Add("q", "Microsoft");
}
// Assign auxilliary parameters required for the search.
Console.WriteLine("Searching " + uriString + " .......");
// Attach QueryString to the WebClient.
myWebClient.set_QueryString(myQueryStringCollection);
// Download the search results Web page into 'searchresult.htm'
// for inspection.
myWebClient.DownloadFile(uriString, "searchresult.htm");
Console.WriteLine("\nDownload of " + uriString + " was successful."
+ " Please see 'searchresult.htm' for results.");
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.