public ActionResult Index(IFormFile postedFile) { if (postedFile != null) { try { //Get uploaded file extension var fileExtension = Path.GetExtension(postedFile.FileName); //Validate uploaded file and return error. if (!Validator.IsValidFIle(fileExtension)) { ViewBag.Message = "Please select valid file. Allowd file formats: .csv, .flf"; return(View()); } //implementing strategy pattern to load business logic as per imported file extension var productInventories = _businessDataContext.InstantiateStrategy <IFileAbstract> (_businessDataContext.ConextStrategy[fileExtension]).ProcessImportedFiles(postedFile); return(View("Result", new ImportedDataDetail { ProductInventories = productInventories, Extension = FormatString.FormatImgUrl(fileExtension) })); } catch (Exception ex) { ViewBag.Message = ex.Message; } } else { ViewBag.Message = "Please select the file to upload."; } return(View()); }