Tom
Tom

Reputation:

How do I upload an image/file using a post request in C#?

C# provides functionality to submit a post request, but there is nothing about uploading an image/file on MSDN. I'd like to do this without using raw headers.

Related questions

Upload files with HTTPWebrequest (multipart/form-data)

Upvotes: 0

Views: 4747

Answers (2)

Chris Hynes
Chris Hynes

Reputation: 10249

My ASP.NET Upload FAQ has an article on this, with example code: Upload files using an RFC 1867 POST request with HttpWebRequest/WebClient. This code doesn't load files into memory, supports multiple files, and supports form values, setting credentials and cookies, etc.

Upvotes: 2

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422280

You can use WebClient class easily. It has an UploadFile method:

var client = new WebClient();
client.UploadFile("http://server/upload.aspx", @"C:\file.jpg");

Upvotes: 3

Related Questions