title: Asp.Net multiple file upload
body: <p>I've set up an asp.net multiple file upload and it works but not in the way I would expect it to.</p>
  
  <p>On my page I've got 2 image uploaders like so</p>
  
  <pre><code>&lt;input type="file" id="gallery" class="multi" accept="jpg" runat="server" /&gt;
  
  &lt;input type="file" id="pic1" accept="jpg" runat="server" /&gt;
  </code></pre>
  
  <p>My problem is when I upload it uses this code </p>
  
  <pre><code>Dim hfc As HttpFileCollection = Request.Files
  </code></pre>
  
  <p>To get all the files which were posted but I only want <code>gallery</code> images for this specific method.</p>
  
  <p>I have a different method to upload my other image.</p>
  
  <p>I've tried changing it to the following </p>
  
  <pre><code>Dim hfc As HttpFileCollection = Request.Files("gallery")
  </code></pre>
  
  <p>But I get an error </p>
  
  <blockquote>
    <p>Value of type 'System.Web.HttpPostedFile' cannot be converted to 'System.Web.HttpFileCollection'.</p>
  </blockquote>
  
  <p>Any ideas how I can accomplish this?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here's the full piece of code I'm working with</p>
  
  <pre><code>Dim hfc As HttpFileCollection = Request.Files("gallery")
  For i As Integer = 0 To hfc.Count - 1
  Dim hpf As HttpPostedFile = hfc(i)
  If hpf.ContentLength &gt; 0 Then
      hpf.SaveAs(Server.MapPath("/images/" &amp; i &amp; ".jpg"))
  End If
  Next i
  </code></pre>
  
  <p>When I use the code from the answer below I get an error saying</p>
  
  <blockquote>
    <p>'Count' is not a member of 'System.Web.HttpPostedFile'.</p>
  </blockquote>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>This works with uploading all my images</p>
  
  <pre><code>Dim hfc As HttpFileCollection = Request.Files
  For i As Integer = 0 To hfc.Count - 1
  Dim hpf As HttpPostedFile = hfc(i)
  If hpf.ContentLength &gt; 0 Then
  hpf.SaveAs(Server.MapPath("/images/" &amp; i &amp; ".jpg"))
  End If
  Next i
  </code></pre>
  
  <p>But it uploads every image - I just want it to upload files posted from </p>
  
  <p><code>&lt;input type="file" id="gallery" class="multi" accept="jpg" runat="server" /&gt;</code> </p>
  
  <p>and not this one as well</p>
  
  <pre><code>&lt;input type="file" id="pic1" accept="jpg" runat="server" /&gt;
  </code></pre>