public ActionResult UploadPSLPartExcel() { try { if (Request.Files.Count > 0) { var file = Request.Files["file"]; string response = Common.ValidateFileUpload(file); if (response.Equals("true")) { if (file != null) { var fileName = "PSLPart_File" + Path.GetExtension(file.FileName); var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Upload/Document/"), fileName); file.SaveAs(path); string csvConnectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + path + ";Extensions=asc,csv,tab,txt;Persist Security Info=False"; string oleDbConnectionString = $@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={path};Extended Properties=""Excel 12.0 Xml;HDR=YES"""; DataTable dataTable = _mepBusinessService.CreateTablePSLPart(path); _mepBusinessService.BulkUpdatePSLPart(dataTable, WebConfigure.GetMainConnectionString()); } } } return(Content("<script language='javascript' type='text/javascript'>alert('Upload PSLPart Data Excel is Successfull'); location.href = '" + WebConfigure.GetDomain() + "/Admin/Default/Index';</script>")); } catch (Exception ex) { _logErrorBService.WriteLog("Admin Upload PSLPart", MethodBase.GetCurrentMethod().Name, ex.ToString()); return(Content("<script language='javascript' type='text/javascript'>alert('Upload PSLPart Data was Failed, Please Make to Sure About Format File and then upload again'); location.href = '" + WebConfigure.GetDomain() + "/Admin/Default/Index';</script>")); } }
public ActionResult UploadMepExcel() { try { if (Request.Files.Count > 0) { var file = Request.Files["file"]; string response = Common.ValidateFileUpload(file); if (response.Equals("true")) { if (file != null) { var fileName = "MEP" + Path.GetExtension(file.FileName); var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Upload/"), fileName); file.SaveAs(path); string oleDbConnectionString = $@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={path};Extended Properties=""Excel 12.0 Xml;HDR=YES"""; DataTable dataTable = _mepBusinessService.CreateDataTable(oleDbConnectionString); _mepBusinessService.BulkUpdateMep(dataTable, WebConfigure.GetMainConnectionString()); } } } return(Content("<script language='javascript' type='text/javascript'>alert('Upload MEP Excel was Successfull'); location.href = '" + WebConfigure.GetDomain() + "/Admin/Default/Index';</script>")); } catch { return(Content("<script language='javascript' type='text/javascript'>alert('Upload MEP Excel was Failed, Please Make to Sure about format file to upload then'); location.href = '" + WebConfigure.GetDomain() + "/Admin/Default/Index';</script>")); } }