title: Accessing input type file at server side in asp.net
body: <p>I am using the <code>&lt;input type="file" /&gt;</code> tag to upload a file to the server. How do I access the file at the server side and store it at the server? (The file is an image file)</p>
  
  <p>The client side code is :</p>
  
  <pre><code>&lt;form id="form1" action="PhotoStore.aspx" enctype="multipart/form-data"&gt;
      &lt;div&gt;
      &lt;input type="file" id="file" onchange="preview(this)" /&gt;
      &lt;input type="submit" /&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Photostore.aspx.cs has</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
              int index = 1;
              foreach (HttpPostedFile postedFile in Request.Files)
              {
                  int contentLength = postedFile.ContentLength;
                  string contentType = postedFile.ContentType;
                  string fileName = postedFile.FileName;
  
                  postedFile.SaveAs(@"c:\test\file" + index + ".tmp");
  
                  index++;
              } 
  
          }
  </code></pre>
  
  <p>I tried uploading a jpg file. Not able to see a saved file. What is going wrong?</p>