user42931
user42931

Reputation: 1165

C# .NET Uploading file to a web form using HttpWebRequest

Does anyone have a working example using HttpWebRequest in C# to submit a file from the local drive to a multipart/form-data web form?

Upvotes: 2

Views: 6005

Answers (1)

Matt Briggs
Matt Briggs

Reputation: 42248

it is WAY easier to do this with WebClient

string url = "http://myserver/myapp/upload.aspx";
string file = "c:\\files\\test.jpg";
WebClient wc = new WebClient();
wc.UploadFile(url,"post",file);

If it needs to be httpwebrequest I can put something together for you (it is possible), but it will be more like 50 lines then 5

Upvotes: 10

Related Questions