title: How to validate CSV files lines, before importing them
body: <p>I have the following flat file:</p>
  
  <p><a href="https://www.screencast.com/t/42mFZIrB04b" rel="nofollow noreferrer">https://www.screencast.com/t/42mFZIrB04b</a></p>
  
  <p>As you can see there is a ROW that is apparently not formatted correctly.</p>
  
  <p>I have the following code:</p>
  
  <pre><code> public class FlatFileModel
      {
          public string Key { get; set; }
          public string ArticleNumber { get; set; }
          public string ColorCode { get; set; }
          public string Description { get; set; }
          public string Price { get; set; }
          public string ActionPrice { get; set; }
          public string Delivery { get; set; }
          public string Q1 { get; set; }
          public string Size { get; set; }
          public string Color { get; set; }
      }
  
  
  
  
  [HttpPost]
          public ActionResult Upload()
          {
              if (Request.Files.Count &gt; 0)
              {
                  var httpPostedFileBase = Request.Files[0];
                  if (httpPostedFileBase != null &amp;&amp; httpPostedFileBase.ContentLength &gt; 0)
                  {
                      //read data from input stream
                      using (var csvReader = new System.IO.StreamReader(httpPostedFileBase.InputStream))
                      {
                          string inputLine = "";
  
                          List&lt;FlatFileModel&gt; lineaArchivo = new  List&lt;FlatFileModel&gt;();
                          //read each line
                          while ((inputLine = csvReader.ReadLine()) != null)
                          {
                              //get lines values
                              string[] values = inputLine.Split(new char[] { ',' });
  
                              for (int x = 0; x &lt; values.Length; x++)
                              {
                                  lineaArchivo.Add(new FlatFileModel()
                                  {
                                      Key = values[0],
                                      ArticleNumber = values[1],
                                      ColorCode = values[2],
                                      Description = values[3],
                                      Price = values[4],
                                      ActionPrice = values[5],
                                      Delivery = values[6],
                                      Q1 = values[7],
                                      Size = values[8],
                                      Color = values[9]
                                  });
                              }
                          }
  
                          csvReader.Close();
                      }
                  }
                  //var file = Request.Files[0];
  
                  //if (file != null &amp;&amp; file.ContentLength &gt; 0)
                  //{
                  //    var fileName = Path.GetFileName(file.FileName);
                  //    var path = Path.Combine(Server.MapPath("~/CSVs/"), fileName);
                  //    file.SaveAs(path);
                  //}
              }
  
              return RedirectToAction("Index");
          }
  </code></pre>
  
  <p>I need an easy way to detect the ROWS that wont fit into the format, so Ican just ignore them, or LOG them as error, but I am not sure how can I do that.</p>
  
  <p>Thanks</p>