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:
StreamReader reader = new StreamReader(File.OpenRead(attachmentcsv));
File is underlined saying
Controller.File(byte[].string) is a method, which is not valid in the current context
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?
[HttpPost]
public ActionResult CreateBulk(HttpPostedFileBase attachmentcsv)
{
StreamReader reader = new StreamReader(File.OpenRead(attachmentcsv));
List<string> clientN = new List<String>();
List<string> homePage = new List<String>();
List<string> clientEmail = new List<String>();
List<string> contName = new List<String>();
List<string> monthlyQuota = new List<String>();
List<string> MJTopicsID = new List<String>();
//string vara1, vara2, vara3, vara4;
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (!String.IsNullOrWhiteSpace(line))
{
string[] values = line.Split(',');
if (values.Length >= 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 => c.ApplicationUserId == userId).First().ID;
for (int i = 0; i < 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");
}