Sunday, May 1, 2011

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)

From stackoverflow
  • 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 : In that case, I'm afraid your question is essentially a dupe of the one linked above.
  • 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.

0 comments:

Post a Comment