How to upload multiple files using webclient UploadFile, UploadValues in C#?
This blog post details exactly how to upload multiple files using WebClient.
If you want to upload both form fields and a file in the same POST, you can't use WebClient as-is-- instead it will need to be extended. Here's an excerpt from this article explaining what is needed:
the only option is to create a custom implementation that conforms to rfc1867, rfc2388 and the W3C multipart/form-data specification that will enable file upload with additional form fields and exposes control of cookies and headers.
Here are three implementations, using slightly different approaches, but all should work to enable multi-part form data:
WebClient.UploadValues is not designed to upload files-- instead it's used to send POST-ed form values to the server. You want to use WebClient.UploadFile to upload files, or one of the advanced samples above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With