title: How to upload an image programmatically using C#
body: <p>I am trying to simulate a file upload to a website. I have an html form like this:</p>
  
  <pre><code>&lt;input name="upl" type="file" style="width:266px" value="File" id="file_input_box" onchange="AFUpload.ad_placement(this.form.upl, 5242880)"&gt;
  </code></pre>
  
  <p>or </p>
  
  <pre><code>&lt;input type="file" name="file" onchange="StartUpload(this.form, this.form.file.value)" size="40" style="margin-top:5px;"&gt;
  </code></pre>
  
  <p>This open standard "open file dialog box", for uploading a file, in this case an image. I want to upload an image but not by clicking the button.</p>
  
  <p>Is this close or just stupid?</p>
  
  <pre><code>void Set(string tagname, string attribute, string attName, string value)
          {
  
              HtmlElementCollection tagsCollection = webBrowser1.Document.GetElementsByTagName(tagname);
  
              foreach (HtmlElement currentTag in tagsCollection)
              {
  
                  if (currentTag.GetAttribute(attribute).Equals(attName))
  
                      currentTag.SetAttribute("value", value);
              }
          }
  
  
  Set("input", "name", "upl", @"C:\image.jpg");
  </code></pre>