bytecode77 bytecode77 - 8 months ago 49
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.