Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get server response with WebClient.UploadFileAsync method

Tags:

c#

webclient

I am using WebClient.UploadFileAsync to upload local files to a web server and I am wondering if it is possible to get the any responses from the server after the upload is complete?

When using WebClient.UploadFile it is possible to get a byte array containing any response. But I would like to do the upload asynchronously.

Thanks.

like image 584
Keith Maurino Avatar asked Aug 30 '11 20:08

Keith Maurino


1 Answers

Subscribe to the UploadFileCompleted event

From MSDN:

client.UploadFileCompleted += new UploadFileCompletedEventHandler (UploadFileCallback);

....

private static void UploadFileCallback(Object sender, UploadFileCompletedEventArgs e)
{
    string reply = System.Text.Encoding.UTF8.GetString (e.Result);
    Console.WriteLine (reply);
}
like image 152
jglouie Avatar answered Nov 15 '22 22:11

jglouie