public ActionResult Import(SandboxImportModel model) { try { if (model.ListStores == null) { ModelState.AddModelError("ListStores", "Please choose language."); return(View(model)); } if (model.ExcelUpload == null || model.ExcelUpload.ContentLength <= 0) { ModelState.AddModelError("ListStores", "Excel filename cannot be null"); return(View(model)); } ImportModel importModel = new ImportModel(); string msg = ""; // read excel file if (model.ExcelUpload != null && model.ExcelUpload.ContentLength > 0) { string fileName = Path.GetFileName(model.ExcelUpload.FileName); string filePath = string.Format("{0}/{1}", System.Web.HttpContext.Current.Server.MapPath("~/Uploads"), fileName); //upload file to server if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } model.ExcelUpload.SaveAs(filePath); importModel = _LanguageFactory.Import(filePath, model.ListStores[0], "Admin", ref msg); //delete file excel after insert to database if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } if (msg.Equals("")) { return(View("ImportDetail", importModel)); } else { _logger.Error("Language_Import: " + msg); ModelState.AddModelError("ListStores", msg); return(View(model)); } } catch (Exception e) { _logger.Error("Language_Import: " + e); ModelState.AddModelError("ListStores", "Import file have error."); return(View(model)); } }