title: C# Multipart Form post with image upload
body: <p>I am not very familiar with streams but googling got me some code but its not working. I want to upload a image to a server that accept a post in multipartform 
  here is my code, its not working and i dont know if its correct or not. Please guide</p>
  
  <pre><code> MemoryStream stream;
                              using ( stream = new MemoryStream())
                              {
                                  using (var writer = new StreamWriter(stream))
                                  {
                                      writer.Write("multipart/form-data; boundary=---------------------------" + ak);
                                      if (image_path1.ToLower().Contains("png"))
                                      {
                                          writer.Write("Content-Disposition: form-data;");
                                          writer.Write("name=img;");
                                          writer.Write("filename="+name+";");
                                          writer.Write("Content-Type: image/png");
                                      }
                                      else
                                      {
                                          writer.Write("Content-Disposition: form-data;");
                                          writer.Write("name=img;");
                                          writer.Write("filename=" + name + ";");
                                          writer.Write("Content-Type: image/jpeg");
                                      }
                                      writer.Flush();
  
                                      var file1 = File.ReadAllBytes(image_path1);
                                      stream.Write(file1, 0, file1.Length);
                                     // stream.Flush();
                                  }
                              }
  </code></pre>
  
  <p>Next i dont even know how to post it, for normal post i using like this</p>
  
  <pre><code>string response = client.Post(domain, post_string);
  </code></pre>
  
  <p>I have to create request like this <a href="http://prntscr.com/1gje7l" rel="nofollow">http://prntscr.com/1gje7l</a> 
  and functions are  <a href="http://prntscr.com/1gjefr" rel="nofollow">http://prntscr.com/1gjefr</a></p>