bytecode77 bytecode77 - 1 year ago 81
C# Question

How can I specify form name in WebClient.UploadFile?

is a very decent layer of abstraction when compared to
, in most situations.

using (WebClient webClient = new WebClient())
return webClient.UploadFile(url, path);

However, the class doesn't seem to include an option for the name of the input field. Here,
must be the name of the input field.

From Wireshark

Content-Disposition: form-data; name="file"; filename="test.txt"

Is there a way to specify the "name" field, without going back to HttpPostRequest?

Answer Source

It would appear that this is hardcoded. View source here for WebClient, head to line 573.

Looks like you will have to implement that portion yourself if you would like to do that. I found blog post that looked promising (since it had the name customized). You can find that here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download