public IActionResult Index(FormData model) { XlDataTable = HttpContext.Session.Get <DataTable>("MyTable"); model.AddFileName(HttpContext.Session.Get <string>("name")) .AddRowElementList(SplitData(XlDataTable, model)); return(View("Index", model)); }
public async Task <IActionResult> Index(IFormFile file) { FormData formData = null; if (ModelState.IsValid) { if (file != null) { formData = new FormData(); var filePath = Path.GetTempFileName(); FileName = Path.GetFileName(file.FileName); TempFileName = System.Guid.NewGuid().ToString() + '_' + FileName; var path = Path.Combine( Directory.GetCurrentDirectory(), "Temp", TempFileName); using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite)) { await file.CopyToAsync(fileStream); fileStream.Close(); XlDataTable = GetXlDatatable(path); System.IO.File.Delete(path); } formData.AddFileName(FileName); } else { ModelState.AddModelError("File", "Please Upload Your file"); } } HttpContext.Session.Set <DataTable>("MyTable", XlDataTable); HttpContext.Session.Set <string>("name", FileName); return(View(formData)); }