public List <FileContent> UploadFile(bool isChangeName) { List <FileContent> lstFiles = new List <FileContent>(); try { string origFilename = ""; var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { var docfiles = new List <string>(); foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; FileData data = new FileData(); //bool isChangeName = Convert.ToBoolean(HttpContext.Current.Request.Form["isChangeName"].ToString()); data.fileName = postedFile.FileName; if (data.fileName.LastIndexOf("\\") > 0) { data.fileName = data.fileName.Substring(data.fileName.LastIndexOf("\\") + 1); } origFilename = data.fileName; data.fileName = isChangeName ? origFilename.Split('.')[0] + "_" + DateTime.Now.ToString("MMddyyhhmmsstt") + "." + origFilename.Split('.')[1] : data.fileName; data.fileStatus = "1"; data.fileSize = postedFile.ContentLength.ToString(); //data.locationIds = HttpContext.Current.Request.Form["locationIds"]; // data.uploadDateTime = HttpContext.Current.Request.Form["startDate"] != "" ? HttpContext.Current.Request.Form["startDate"] : DateTime.Now.ToString("dd-MM-yyyy"); data.locationName = HttpContext.Current.Request.Form["locations"]; //data.customerIds = HttpContext.Current.Request.Form["CustomerId"]; data.customerAdminId = HttpContext.Current.Request.Form["CustomerId"]; data.customerName = HttpContext.Current.Request.Form["customerName"]; List <string> locationsList = JsonConvert.DeserializeObject <List <string> >(data.locationName); foreach (string location in locationsList) { // (@appUserId,@fileName,@fileStatusId,@uploadDateTime,@fileSize,@locationId,@filePath,@fullPath,@mediaType,@customerId)"; if (location != "") { FileContent fCont = new FileContent(); string strPath = "\\" + location.Replace(' ', '-').ToLower() + "\\Pending\\"; string dirPath = imagesFolder + strPath; string mediaJson = ""; mediaJson = dirPath + jsonFileNameMeidaShow; if (!Directory.Exists(dirPath)) { DirectoryInfo di = Directory.CreateDirectory(dirPath); if (Directory.Exists(dirPath)) { try { File.Copy(jsonMediaTemplateFilePath, di.FullName + jsonFileNameMeidaShow); File.Copy(jsonPpShowlistFilePath, di.FullName + jsonFileNamePpShowlist); } catch { } } } string fullpath = imagesFolder + strPath + data.fileName; postedFile.SaveAs(fullpath); data.filePath = strPath + data.fileName; data.fullPath = fullpath; data.locationName = location; fCont.appUserId = Convert.ToInt32(HttpContext.Current.Request.Form["UserId"]); fCont.fileName = data.fileName; fCont.fileStatusId = (int)Constants.FileStatus.pending; fCont.fileSize = data.fileSize; fCont.customerId = Convert.ToInt32(HttpContext.Current.Request.Form["CustomerId"]); fCont.appUserId = Convert.ToInt32(HttpContext.Current.Request.Form["appUserId"]); fCont.locationName = data.locationName; fCont.filePath = data.filePath; fCont.fullPath = data.fullPath; fCont.origFileName = origFilename; fCont.mediaTypeId = (int)(Constants.MediaExtnType)Enum.Parse(typeof(Constants.MediaExtnType), data.MediaType().ToString()); fCont.origFilePath = strPath + origFilename; fCont.origFullPath = imagesFolder + strPath + origFilename; lstFiles.Add(fCont); MediajsonHandler mh = MediajsonHandler.Instance; mh.writeToMediaJson(mediaJson, data, false); } } } } } catch (Exception ex) { } return(lstFiles); }