public ActionResult ImportConsumer(HttpPostedFileBase file, BALExportConsumer model, string Command) { DALExportConsumer dalExportConsumer = new DALExportConsumer(); ImportConsumer importConsumer =new ImportConsumer(); LoginSession loginsession = (LoginSession)Session["Login"]; try { if (Command == "Export") { if (importConsumer.ImportExcel(Convert.ToString(model.SiteID))) { string filepath = Path.Combine(Server.MapPath("~/Upload"), "ConsumerTemplate.xlsx"); var fileName = "ConsumerTemplate.xlsx"; var mimeType = "application/vnd.ms-excel"; return File(new FileStream(filepath, FileMode.OpenOrCreate), mimeType, fileName); } else { if (loginsession.ClientID != null) { ViewBag.Client = new SelectList(BAL.ClientModel.ClientDropDownList(loginsession.ClientID), "Value", "Text"); } else { ViewBag.Client = new SelectList(BAL.ClientModel.ClientDropDownList(), "Value", "Text"); } //ViewBag.Message = "Record is Empty"; } } else if (Command == "Submit") { ViewBag.Isload = true; string extension = Path.GetExtension(file.FileName); fileName = string.Format(@"{0}." + extension, Guid.NewGuid()); var path = Path.Combine(Server.MapPath("~/ExportFileUpload"), fileName); file.SaveAs(path); //Get Excel Column model.ItemList = dalExportConsumer.getExcelColumnName(path); //Get DB Table Column model.ListtblColumnName = dalExportConsumer.GetTableColumnName("SYCOUS.Consumer"); Session["DBColumnNameConsumer"] = model.ListtblColumnName; Session["FilePathConsumer"] = Path.Combine(Server.MapPath("~/ExportFileUpload"), fileName); if (loginsession.ClientID != null) { ViewBag.Client = new SelectList(BAL.ClientModel.ClientDropDownList(loginsession.ClientID), "Value", "Text"); } else { ViewBag.Client = new SelectList(BAL.ClientModel.ClientDropDownList(), "Value", "Text"); } } } catch (Exception Ex) { ViewBag.Isload = false; if (loginsession.ClientID != null) { ViewBag.Client = new SelectList(BAL.ClientModel.ClientDropDownList(loginsession.ClientID), "Value", "Text"); } else { ViewBag.Client = new SelectList(BAL.ClientModel.ClientDropDownList(), "Value", "Text"); } ViewBag.Message = Ex.Message; } return View(model); }