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.
+2
A:
You can use WebClient
class easily. It has an UploadFile
method:
var client = new WebClient();
client.UploadFile("http://server/upload.aspx", @"C:\file.jpg");
Mehrdad Afshari
2009-04-20 10:57:41
I'd like to upload a file and submit other post variables at the same time. Any idea how I'd do that?
2009-04-20 15:42:49
In that case, I'm afraid your question is essentially a dupe of the one linked above.
Mehrdad Afshari
2009-04-20 15:58:38
The one linked above doesn't include post variables. UploadFile() doesn't let me specify any other form values (name, board) which need to be set in order to upload the image.
2009-04-21 15:58:17
+1
A:
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.
Chris Hynes
2009-04-23 17:35:59