public ActionResult NewFileProcessing(UploadCsvFileViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } string fileExt = Path.GetExtension(viewModel.UpLoadedCsvFile.FileName).ToUpper(); if (fileExt == ".CSV") { string fileName = Path.GetFileName(viewModel.UpLoadedCsvFile.FileName); string path = AppDomain.CurrentDomain.BaseDirectory + "Upload\\" + fileName; viewModel.UpLoadedCsvFile.SaveAs(path); using (StreamReader input = System.IO.File.OpenText(path)) using (CsvReader csvReader = new CsvReader(input, CultureInfo.InvariantCulture)) { IEnumerable <CsvRecord> records = csvReader.GetRecords <CsvRecord>(); csvReader.Configuration.Delimiter = ";"; csvReader.Configuration.IgnoreBlankLines = true; csvReader.Configuration.MissingFieldFound = null; csvReader.Configuration.RegisterClassMap <CsvRecordMap>(); //Processing records to seed the database SeedDatabase(records); } return(RedirectToAction("Index", "DataShow")); } else { ViewData["error"] = "upload failed"; return(View(viewModel)); } }
public ActionResult NewFileProcessing() { var uploadedFile = new UploadCsvFileViewModel(); return(View(uploadedFile)); }