title: HTTPRequest.Files.Count Never Equals Zero
body: <p>I have a form on an HTML page that a user needs to use to upload a file which posts to an ASPX page. In the code behind, I want to test if a file has actually been loaded.</p>
  
  <pre><code>if (Request.Files.Count &gt; 0)
  {
      DoStuff(Request.Files[0]);
  }
  else
  {
      throw new Exception("A CSV file must be selected for upload.");
  }
  </code></pre>
  
  <p>I am never getting to the else. Is this just how ASP.NET operates? If I have a input element of type file, is it always going to upload a "file" even if one is not selected?</p>
  
  <p>What's the proper way to do this? Maybe this?</p>
  
  <pre><code>if (Request.Files.Count &gt; 0 &amp;&amp; Request.Files[0].ContentLength &gt; 0)
  {
      DoStuff(Request.Files[0]);
  }
  else
  {
      throw new Exception("A CSV file must be selected for upload.");
  }
  </code></pre>