title: Reading .csv file from Multipart Content - not read as FileData
body: <p>I am building a WebAPI call which takes an uploaded .csv file, reads that file, and then takes action based on the contents. At least, that's what it should do.</p>
  
  <p>I'm working with code found in the <a href="https://www.asp.net/web-api/overview/advanced/sending-html-form-data-part-2" rel="nofollow noreferrer">ASP.NET documentation</a> and in many other places, all of which indicate that my file contents should be read into <code>provider.FileData</code>. However, they are being read into <code>provider.FormData</code> as if they were more generic form elements. It exists there as one long string, with inconsistent separators and no key/value pairs to work with. I've been poring over SO questions but haven't found anything that helps.</p>
  
  <p>How can I either get the file to read into FileData, or parse the contents from FormData?</p>
  
  <p>In Controller:</p>
  
  <pre><code>    public async Task&lt;HttpResponseMessage&gt; ImportPersons()
      {
          if (!Request.Content.IsMimeMultipartContent())
              throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
  
          var provider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("~/App_Data"));
          await Request.Content.ReadAsMultipartAsync(provider);
  
          if (!provider.FileData.Any()) //evaluated as true
              throw new InvalidOperationException("File does not contain any data.");
  
          var personsToImport = new List&lt;Persons&gt;();
          foreach (var record in provider.FileData)
          {
             //handle file contents
             //code omitted
          }
  </code></pre>
  
  <p>In View (simplified):</p>
  
  <p>I guessed that the program might be seeing my file as a simple form input based on where it ended up, but changing this to include just a single file upload input didn't affect the issue.</p>
  
  <pre><code>@using (Html.BeginForm("Import", "Persons", FormMethod.Post, new { enctype = "multipart/form-data" }))
  {
  &lt;fieldset&gt;
      &lt;div &gt;
          &lt;input type="text" disabled/&gt;
          &lt;span&gt;
              &lt;input type="file" name="FileUpload" id="FileUpload" accept=".csv" required /&gt;
              Browse...
          &lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="form-submit"&gt;
          &lt;a href="@Url.Action("Index", "Persons")"&gt;Cancel&lt;/a&gt;
          &lt;input type="submit" value="Import File"/&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  }
  </code></pre>