开发者

How to upload multiple files using webclient UploadFile, UploadValues in C#?

开发者 https://www.devze.com 2023-01-01 13:59 出处:网络
How to upload 开发者_StackOverflow社区multiple files using webclient UploadFile, UploadValues in C#?This blog post details exactly how to upload multiple files using WebClient.

How to upload 开发者_StackOverflow社区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:

  • http://www.codeproject.com/Articles/72232/Csharp-File-Upload-with-form-fields-cookies-and-he.aspx
  • http://www.codeproject.com/KB/cs/uploadfileex.aspx
  • http://aspnetupload.com/Upload-File-POST-HttpWebRequest-WebClient-RFC-1867.aspx

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号