public ActionResult AddDUNSMonitoringPlus(string RegistrationsName, HttpPostedFileBase file, string AuthToken) { if (file != null && CommonMethod.CheckFileType(".txt", file.FileName.ToLower())) { if (file.ContentLength > 0) { string path = string.Empty; string url = Request.Url.Authority; string tempDirectory = "~/Upload/MonitoringDirectPlusAddDuns/" + url; string directory = Server.MapPath(tempDirectory.Replace(":", "")); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string FileName = System.DateTime.Now.Ticks + "_" + file.FileName; path = Path.Combine(directory, Path.GetFileName(FileName)); file.SaveAs(path); path = CheckNumberOfLinesINDUNSRegistration(path); Utility.Utility utility = new Utility.Utility(); AddRemoveDUNSToMonitoringResponse addDUNsToMonitoringResponse = utility.AddDunsToMonitoring(RegistrationsName, path, AuthToken); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } if (addDUNsToMonitoringResponse.information != null && !string.IsNullOrEmpty(addDUNsToMonitoringResponse.information.message)) { return(Json(new { result = false, message = addDUNsToMonitoringResponse.information.message }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { result = false, message = addDUNsToMonitoringResponse.error.errorMessage }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { result = false, message = CommonMessagesLang.msgCommanFileEmpty }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { result = false, message = CommonMessagesLang.msgInvalidFile }, JsonRequestBehavior.AllowGet)); } }
public JsonResult ImportData(HttpPostedFileBase file, bool header) { if (file != null && CommonMethod.CheckFileType(".xls,.xlsx,", file.FileName)) { if (file.ContentLength > 0) { DataTable dt = new DataTable(); string path = string.Empty; try { string directory = Server.MapPath("~/Content/UploadDataFile"); if (!Directory.Exists(directory)) { DirectoryInfo di = Directory.CreateDirectory(directory); } //change file name with current date & time string[] strfileName = file.FileName.Split('.'); string extension = strfileName[strfileName.Count() - 1]; string fileName = System.DateTime.Now.Ticks + "." + extension; TempData["fileName"] = fileName; path = Path.Combine(directory, Path.GetFileName(fileName)); file.SaveAs(path); //convert Excel file to data table dt = DataController.ExcelToDataTable(path, header); TempData["Data"] = dt; System.IO.File.Delete(path); } catch (Exception ex) { System.IO.File.Delete(path); if (ex.Message.Contains("already belongs to this DataTable")) { return(new JsonResult { Data = ex.Message.Replace("DataTable", "file") }); } else { return(new JsonResult { Data = "Error:" + ex.Message }); } } } else { return(new JsonResult { Data = MessageCollection.CommanFileEmpty }); } } else { return(new JsonResult { Data = MessageCollection.CommanChechExcelFile }); } TempData.Keep(); return(new JsonResult { Data = "success" }); }
public ActionResult BindColumnMapping(HttpPostedFileBase file, string ImportType, string CustmDelimtr) { string fileType = ""; DataTable dt = new DataTable(); bool IsTag = false; bool IsInLanguage = false; List <SelectListItem> lstAllFilter = new List <SelectListItem>(); if (file != null && CommonMethod.CheckFileType(".xls,.xlsx,.csv,.tsv,.txt", file.FileName.ToLower())) { string path = string.Empty; string url = Request.Url.Authority; string UserId = Helper.oUser.UserId.ToString(); string tempDirectory = "~/Upload/UploadCommandFile/" + url + "/" + UserId; string directory = Server.MapPath(tempDirectory.Replace(":", "")); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } FileInfo oFileInfo = new FileInfo(file.FileName); string fileExtension = oFileInfo.Extension; string fileName = System.DateTime.Now.Ticks + fileExtension; path = Path.Combine(directory, Path.GetFileName(fileName)); file.SaveAs(path); string extension = Path.GetExtension(file.FileName); // Read excel file & set column header in datatable if (extension.ToLower() == ".xls" || extension.ToLower() == ".xlsx") { IExcelDataReader reader = null; FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); if (extension.Equals(".xls")) { reader = ExcelReaderFactory.CreateBinaryReader(stream); } else if (extension.Equals(".xlsx")) { reader = ExcelReaderFactory.CreateOpenXmlReader(stream); } if (reader != null) { var conf = new ExcelDataSetConfiguration { ConfigureDataTable = _ => new ExcelDataTableConfiguration { UseHeaderRow = true } }; //Fill DataSet DataSet content = reader.AsDataSet(conf); dt = content.Tables[0]; } stream.Close(); } // Read csv,tsv & delimiter file & set column header in datatable else if (extension.ToLower() == ".csv" || extension.ToLower() == ".txt") { string Delimiters = string.Empty; if (extension.ToLower() == ".csv") { Delimiters = ","; } else if (extension.ToLower() == ".txt") { if (string.IsNullOrEmpty(CustmDelimtr)) { Delimiters = "\t"; } else { Delimiters = CustmDelimtr; } } using (TextFieldParser csvReader = new TextFieldParser(path)) { try { csvReader.SetDelimiters(Delimiters); csvReader.HasFieldsEnclosedInQuotes = true; //read column names string[] colFields = null; colFields = csvReader.ReadFields(); foreach (string column in colFields) { DataColumn datecolumn = new DataColumn(column); dt.Columns.Add(datecolumn); } } catch (Exception) { dt = new DataTable(); System.IO.File.Delete(path); IPagedList <dynamic> pagedProducts1 = new StaticPagedList <dynamic>(new List <dynamic>(), 1, 10000, 0); return(PartialView("_bindColumnMapping", pagedProducts1)); } } } if (dt != null && dt.Columns != null && dt.Columns.Count > 0) { Helper.InitLookups(); foreach (var item in dt.Columns) { if (Helper.IsSpecialCharactersExist(item.ToString())) { return(Json(new { result = false, message = ImportDataLang.msgError + ":" + ImportDataLang.msgSpecialCharError })); } } lstAllFilter.Add(new SelectListItem { Value = "0", Text = "-Select-" }); int i = 0; foreach (DataColumn c in dt.Columns) { lstAllFilter.Add(new SelectListItem { Value = (i + 1).ToString(), Text = Convert.ToString(c.ColumnName) }); i++; if (c.ColumnName.ToLower() == "tags" || c.ColumnName.ToLower() == "tag") { IsTag = true; } if (c.ColumnName.ToLower() == "language" || c.ColumnName.ToLower() == "language values" || c.ColumnName.ToLower() == "languagevalues" || c.ColumnName.ToLower() == "language code" || c.ColumnName.ToLower() == "languagecode") { IsInLanguage = true; } } } System.IO.File.Delete(path); } List <string> columnName = GetcolumnName(ImportType, this.CurrentClient.ApplicationDBConnectionString); ViewBag.ColumnList = columnName; ViewBag.ExternalColumn = lstAllFilter; ViewBag.IsContainsTags = IsTag; SessionHelper.CommandMapping_IsInLanguage = IsInLanguage; IPagedList <dynamic> pagedProducts = new StaticPagedList <dynamic>(new List <dynamic>(), 1, 10000, 0); ViewBag.fileType = fileType; ViewBag.ImportMode = ImportType; if (ImportType.ToLower().Trim() == "orb data import" || ImportType.ToLower().Trim() == "orb match refresh") { return(PartialView("_bindOrbColumnMapping", pagedProducts)); } return(PartialView("_bindColumnMapping", pagedProducts)); }
public ActionResult UploadImage(HttpPostedFileBase file, int?TicketId) { List <string> lstFiles = new List <string>(); if (CommonMethod.CheckFileType(".jpg,.jpeg,.png,.txt,.docx,.doc,.xlsx,.xls,.pdf", file.FileName.ToLower())) { if (file != null) { FileInfo oFileInfo = new FileInfo(file.FileName); string fileExtension = oFileInfo.Extension; string TicketImage = System.DateTime.Now.Ticks + fileExtension.ToLower(); //Check for uploaded file is image or not if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".jpeg" || fileExtension.ToLower() == ".png") { //Upload Image ImageHelper.UploadImage(file, TicketImage, ImageHelper.PictureType.TicketImage); } else { //Upload Other file ImageHelper.UploadNONImage(file, TicketImage, ImageHelper.PictureType.TicketImage); } //Set ImageName tempdata if (string.IsNullOrEmpty(SessionHelper.ImageName)) { SessionHelper.ImageName = TicketImage; } else { SessionHelper.ImageName = SessionHelper.ImageName + ":" + TicketImage; } string Files = SessionHelper.ImageName.TrimEnd(':'); for (int i = 0; i < Files.Split(':').Length; i++) { if (!string.IsNullOrEmpty(Files.Split(':')[i])) { //Add file in list if it exist on blob if (ImageHelper.IsFileExists(Files.Split(':')[i].ToString(), ImageHelper.PictureType.TicketImage)) { lstFiles.Add(Files.Split(':')[i].ToString()); } } } if (TicketId != null) { //Update Files in ticket table TicketFacade tac = new TicketFacade(StringCipher.Decrypt(Helper.GetMasterConnctionstring(), General.passPhrase)); TicketEntity objTicket = tac.GetTicketByIDByClients(TicketId.Value); // MP-846 Admin database cleanup and code cleanup.-CLIENT objTicket.Files = Files; int result = tac.UpdateTicketFileForClients(objTicket); // MP-846 Admin database cleanup and code cleanup.-CLIENT } } } else { return(new JsonResult { Data = CommonMessagesLang.msgWrongFormat }); } IPagedList <string> pagedProducts = new StaticPagedList <string>(lstFiles, 1, 10000, 0); return(PartialView("_UploadImage", pagedProducts)); }