public JsonResult SaveApplicantQualification(ApplicantQualificationBO Data) { string strResult = ""; if (Request.Files.Count > 0) { string strFileName = ""; string strExtention = ""; Random objRandom = new Random(); string strRandom = objRandom.Next(10000) + ""; string strFileUploadPath = ""; string fileName = ""; string fileContentType = ""; byte[] tempFileBytes = null; dynamic data = null; dynamic types = null; bool result = false; HttpFileCollectionBase files = Request.Files; if (files != null) { for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; if (file.ContentLength == 0) { strResult = "Upload file should not be empty"; } else if (file.ContentLength > 0) { strExtention = Path.GetExtension(file.FileName); fileName = file.FileName; // getting File Name fileContentType = file.ContentType; // getting ContentType tempFileBytes = new byte[file.ContentLength]; // getting filebytes data = file.InputStream.Read(tempFileBytes, 0, Convert.ToInt32(file.ContentLength)); types = CommonUtils.FileType.Image; // Setting Image type if (strExtention.ToUpper() == ".PDF") { types = CommonUtils.FileType.PDF; } else if (strExtention.ToUpper() == ".DOC") { types = CommonUtils.FileType.DOC; } else if (strExtention.ToUpper() == ".DOCX") { types = CommonUtils.FileType.DOCX; } result = CommonUtils.isValidFile(tempFileBytes, types, fileContentType); // Validate Header strFileName = strRandom + "_" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture) + strExtention; var strFileType = file.FileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); if (result) { int FileLength = 1024 * 1024 * 3; //FileLength 3 MB if (file.ContentLength > FileLength) { strResult = "Upload file should not be greater than 3MB"; } Data.AttachmentSavedName = strFileName; strFileUploadPath = strAcademicQualificationUploadPath; strFileName = Path.Combine(strFileUploadPath, strFileName); file.SaveAs(strFileName); } //else //{ // strResult = strResult + "Please Upload Valid file for " + strFileType[0] + "</br>"; //} } } } } UpdateProfileBAL objUpdateProfileBAL = new UpdateProfileBAL(); Data.IsActive = true; strResult = objUpdateProfileBAL.SaveorUpdateApplicantQualification(Data, 1); //if (strResult == "") //{ // strResult = objUpdateProfileBAL.SaveorUpdateApplicantQualification(Data, 1); //} return(Json(strResult, JsonRequestBehavior.AllowGet)); }