title: .NET Csv Parser
body: <p>So I've been trying for the past week to build a CSV parser, I tried Oledb reader but it seemed I had to have a connection string which linked to a certain folder whereas I want a dynamic location. I've now built this which seems like its almost there though on the 4th line:</p>
  
  <pre><code>StreamReader reader = new StreamReader(File.OpenRead(attachmentcsv));
  </code></pre>
  
  <p>File is underlined saying</p>
  
  <blockquote>
    <p>Controller.File(byte[].string) is a method, which is not valid in the current context</p>
  </blockquote>
  
  <p>I assume this means I need to put it in a function, though its the only place I will use it and don't really want to as I struggle with functions is there any alternative?</p>
  
  <pre><code>    [HttpPost]
      public ActionResult CreateBulk(HttpPostedFileBase attachmentcsv)
      {
          StreamReader reader = new StreamReader(File.OpenRead(attachmentcsv));
          List&lt;string&gt; clientN = new List&lt;String&gt;();
          List&lt;string&gt; homePage = new List&lt;String&gt;();
          List&lt;string&gt; clientEmail = new List&lt;String&gt;();
          List&lt;string&gt; contName = new List&lt;String&gt;();
          List&lt;string&gt; monthlyQuota = new List&lt;String&gt;();
          List&lt;string&gt; MJTopicsID = new List&lt;String&gt;();
          //string vara1, vara2, vara3, vara4;
          while (!reader.EndOfStream)
          {
              string line = reader.ReadLine();
              if (!String.IsNullOrWhiteSpace(line))
              {
                  string[] values = line.Split(',');
                  if (values.Length &gt;= 4)
                  {
                      clientN.Add(values[0]);
                      homePage.Add(values[1]);
                      clientEmail.Add(values[2]);
                      contName.Add(values[3]);
                      monthlyQuota.Add(values[4]);
                      MJTopicsID.Add(values[5]);
                  }
              }
          }
          string[] AddclientN = clientN.ToArray();
          string[] AddhomePage = homePage.ToArray();
          string[] AddclientEmail = clientEmail.ToArray();
          string[] AddcontName = contName.ToArray();
          string[] AddmonthlyQuota = contName.ToArray();
          string[] AddMJTopicsID = contName.ToArray();
  
          var userId = User.Identity.GetUserId();
          var UserTableID = db.UserTables.Where(c =&gt; c.ApplicationUserId == userId).First().ID;
  
          for (int i = 0; i &lt; AddclientN.Length; i++)
          {
              String Strip = AddhomePage[i].Replace("https://www.", "").Replace("http://www.", "").Replace("https://", "").Replace("http://", "").Replace("www.", "");
              string[] URLtests = { "https://www." + Strip, "http://www." + Strip, "https://" + Strip, "http://" + Strip };
              string[] Metric = MajesticFunctions.MajesticChecker(URLtests);
              var newclient = new Client { clientN = AddclientN[i], homePage = Metric[0], clientEmail = AddclientEmail[i], contName = AddcontName[i].First().ToString().ToUpper() + AddcontName[i].Substring(1), monthlyQuota = Int32.Parse(AddmonthlyQuota[i]), TrustFlow = Int32.Parse(Metric[1]), CitationFlow = Int32.Parse(Metric[2]), RI = Int32.Parse(Metric[3]), MJTopicsID = Int32.Parse(AddMJTopicsID[i]), UserTableID = UserTableID };
              ViewBag.newdomain = newclient;
              db.Clients.Add(newclient);
              db.SaveChanges();
          }
          return RedirectToAction("Index");
      }
  </code></pre>