Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

WebClient.UploadValues Method

Uploads a name/value collection to a resource with the specified URI.

Overload List

Uploads the specified name/value collection to the specified resource identified by a URI.

[Visual Basic] Overloads Public Function UploadValues(String, NameValueCollection) As Byte()
[C#] public byte[] UploadValues(string, NameValueCollection);
[C++] public: unsigned char UploadValues(String*, NameValueCollection*) __gc[];
[JScript] public function UploadValues(String, NameValueCollection) : Byte[];

Uploads the specified name/value collection to the specified resource with the specified URI using the specified method.

[Visual Basic] Overloads Public Function UploadValues(String, String, NameValueCollection) As Byte()
[C#] public byte[] UploadValues(string, string, NameValueCollection);
[C++] public: unsigned char UploadValues(String*, String*, NameValueCollection*) __gc[];
[JScript] public function UploadValues(String, String, NameValueCollection) : Byte[];

Example

[Visual Basic, C#, C++] The following example gathers information from the user (name, age, and address) and posts the values to the server using UploadValues. Any response from the server is displayed on the console.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of UploadValues. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Console.Write(ControlChars.Cr + "Please enter the URL to post data to : ")
Dim uriString As String = Console.ReadLine()

' Create a new WebClient instance.
Dim myWebClient As New WebClient()

' Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
Dim myNameValueCollection As New NameValueCollection()

Console.WriteLine("Please enter the following parameters to be posted to the Url")
Console.Write("Name:")
Dim name As String = Console.ReadLine()

Console.Write("Age:")
Dim age As String = Console.ReadLine()

Console.Write("Address:")
Dim address As String = Console.ReadLine()

' Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name", name)
myNameValueCollection.Add("Address", address)
myNameValueCollection.Add("Age", age)

Console.WriteLine(ControlChars.Cr + "Uploading to {0} ...", uriString)

' Upload the NameValueCollection.
Dim responseArray As Byte() = myWebClient.UploadValues(uriString, "POST", myNameValueCollection)

' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :" + ControlChars.Cr + "{0}", Encoding.ASCII.GetString(responseArray))

[C#] 
Console.Write("\nPlease enter the URL to post data to : ");
string uriString = Console.ReadLine();

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection myNameValueCollection = new NameValueCollection();

Console.WriteLine("Please enter the following parameters to be posted to the URI");
Console.Write("Name:");
string name = Console.ReadLine();

Console.Write("Age:");
string age = Console.ReadLine();

Console.Write("Address:");
string address = Console.ReadLine();

// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name",name);            
myNameValueCollection.Add("Address",address);
myNameValueCollection.Add("Age",age);
Console.WriteLine("\nUploading to {0} ...",  uriString);

// Upload the NameValueCollection.
byte[] responseArray = myWebClient.UploadValues(uriString,"POST",myNameValueCollection);

// Decode and display the response.
Console.WriteLine("\nResponse received was :\n{0}",Encoding.ASCII.GetString(responseArray));

[C++] 
Console::Write(S"\nPlease enter the URL to post data to : ");
String* uriString = Console::ReadLine();

// Create a new WebClient instance.
WebClient* myWebClient = new WebClient();

// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection* myNameValueCollection = new NameValueCollection();

Console::WriteLine(S"Please enter the following parameters to be posted to the URI");
Console::Write(S"Name:");
String* name = Console::ReadLine();

Console::Write(S"Age:");
String* age = Console::ReadLine();

Console::Write(S"Address:");
String* address = Console::ReadLine();

// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection->Add(S"Name", name);
myNameValueCollection->Add(S"Address", address);
myNameValueCollection->Add(S"Age", age);
Console::WriteLine(S"\nUploading to {0} ...",  uriString);

// Upload the NameValueCollection.
Byte responseArray[] = myWebClient->UploadValues(uriString, S"POST", myNameValueCollection);

// Decode and display the response.
Console::WriteLine(S"\nResponse received was :\n {0}", Encoding::ASCII->GetString(responseArray));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

WebClient Class | WebClient Members | System.Net Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.