public ActionResult SaveDocuments(string strUser = null, int Req = 0) { try { List <DocumentUploadFile> LstDocumentUpload = new List <DocumentUploadFile>(); string FileName = ""; string StrWriteException = string.Empty; for (var i = 0; i <= Req; i++) { if (Request.Files[i] != null) { DocumentUploadFile objUpload = new DocumentUploadFile(); Random rnd = new Random(); int num = rnd.Next(1, 9999); FileName = Request.Files[i].FileName; FileName = FileName.Replace(".", "_" + num.ToString() + "."); var FileStreamBytes = Request.Files[i].InputStream; HttpPostedFileBase file = Request.Files[i]; if (file.ContentLength <= 1000000) { var ext = Path.GetExtension(FileName); DocumentUpload(file, FileName, strUser); } else { StrWriteException = "File Size Exceeded"; var objResult = new { StrWriteException = StrWriteException }; return(Json(objResult, JsonRequestBehavior.AllowGet)); } string directryPath = Server.MapPath("ContactID_" + strUser); FileName = strUser + "_" + FileName; FileName = Path.Combine(directryPath, FileName); objUpload.FileName = FileName; objUpload.Index = i; LstDocumentUpload.Add(objUpload); } } var objRes = new { ObjDocuments = LstDocumentUpload, StrWriteException = StrWriteException }; return(Json(objRes, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var objRes = new { StrWriteException = "Some error occured" }; return(Json(objRes, JsonRequestBehavior.AllowGet)); } }
public ActionResult SaveLeadDocuments(int ContactID, string objLstDoc, int Req = 0) { try { AVOAIALifeEntities Context = new AVOAIALifeEntities(); //string objLstDoc = ""; string DepartmentCode = "", AgentCode = "", DocumentCode = ""; string UserName = User.Identity.Name; AgentCode = Context.tblMasIMOUsers.Where(a => a.UserID == UserName).Select(a => a.AgentCode).FirstOrDefault(); //DepartmentCode = GetMaritialStatus(); List <DocumentUploadFile> LstDocumentUpload = new List <DocumentUploadFile>(); List <DocumentUploadFile> RequestDoc = new List <DocumentUploadFile>(); string FileName = ""; Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); RequestDoc = Newtonsoft.Json.JsonConvert.DeserializeObject <List <DocumentUploadFile> >(objLstDoc, settings); string StrWriteException = string.Empty; for (var i = 0; i < RequestDoc.Count(); i++) { if (string.IsNullOrEmpty(RequestDoc[i].FilePath)) { if (Request.Files[RequestDoc[i].Key] != null) { string Key = RequestDoc[i].Key; DocumentUploadFile objUpload = new DocumentUploadFile(); Random rnd = new Random(); int num = rnd.Next(1, 9999); FileName = Request.Files[Key].FileName; objUpload.FileName = RequestDoc[i].DocName; FileName = FileName.Replace(".", "_" + num.ToString() + "."); var FileStreamBytes = Request.Files[Key].InputStream; HttpPostedFileBase file = Request.Files[Key]; var DocumentNames = RequestDoc[i].DocName; //DocumentCode = Context.tblMasDocuments.Where(a => a.DocumentName == DocumentNames).Select(a => a.DocumentCode).FirstOrDefault(); //if (RequestDoc[i].DocName == "SpouseImage") //{ // DocumentCode = "PRD012"; //} //if (DocumentCode == null) //{ // DocumentCode = "PRD011"; //} DepartmentCode = "Document"; if (file.ContentLength <= 1000000) { var ext = Path.GetExtension(FileName); string _Contact = Convert.ToString(ContactID); string _DepartmentCode = Convert.ToString(DepartmentCode); string _AgentCode = Convert.ToString(AgentCode); //string _DepartmentCode = DepartmentCode; string _DocumentCode = DocumentCode; LeadDocumentUpload(file, FileName, _AgentCode, _Contact, _DocumentCode); } else { StrWriteException = "File Size Exceeded"; var objResult = new { StrWriteException = StrWriteException }; return(Json(objResult, JsonRequestBehavior.AllowGet)); } string directryPath = ConfigurationManager.AppSettings["FileUpload"] + "\\" + AgentCode + "\\" + ContactID; var exts = Path.GetExtension(FileName); FileName = Path.Combine(directryPath, DocumentCode + "" + exts); objUpload.FilePath = FileName; objUpload.ItemType = RequestDoc[i].ItemType; objUpload.MemberType = RequestDoc[i].MemberType; objUpload.Index = i; LstDocumentUpload.Add(objUpload); } } else { DocumentUploadFile objUpload = new DocumentUploadFile(); objUpload.FilePath = RequestDoc[i].FilePath; objUpload.FileName = RequestDoc[i].DocName; objUpload.ItemType = RequestDoc[i].ItemType; objUpload.MemberType = RequestDoc[i].MemberType; objUpload.Index = i; LstDocumentUpload.Add(objUpload); } } string JsonData = JsonConvert.SerializeObject(LstDocumentUpload); var objRes = new { DocData = JsonData, StrWriteException = StrWriteException }; return(Json(objRes, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var objRes = new { StrWriteException = "Some error occured" }; return(Json(objRes, JsonRequestBehavior.AllowGet)); } }
public AIA.Life.Models.Policy.Policy SavePolicyUploadDocuments(AIA.Life.Models.Policy.Policy ObjPolicy) { try { AVOAIALifeEntities Context = new AVOAIALifeEntities(); //string objLstDoc = ""; string DepartmentCode = "", AgentCode = "", DocumentCode = ""; if (ObjPolicy.ProposalNo == "") { ObjPolicy.ProposalNo = "PBBBQ123456"; } string UserName = ObjPolicy.UserName; AgentCode = Context.tblMasIMOUsers.Where(a => a.UserID == UserName).Select(a => a.AgentCode).FirstOrDefault(); //DepartmentCode = GetMaritialStatus(); List <DocumentUploadFile> LstDocumentUpload = new List <DocumentUploadFile>(); List <DocumentUploadFile> RequestDoc = new List <DocumentUploadFile>(); string FileName = ""; Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); RequestDoc = Newtonsoft.Json.JsonConvert.DeserializeObject <List <DocumentUploadFile> >(ObjPolicy.HdnDocumentDetails, settings); string StrWriteException = string.Empty; for (var i = 0; i < RequestDoc.Count(); i++) { if (string.IsNullOrEmpty(RequestDoc[i].FilePath)) { if (Request.Files[RequestDoc[i].Key] != null) { string Key = RequestDoc[i].Key; DocumentUploadFile objUpload = new DocumentUploadFile(); Random rnd = new Random(); int num = rnd.Next(1, 9999); FileName = Request.Files[Key].FileName; objUpload.FileName = RequestDoc[i].DocName; //objUpload.DOCID = RequestDoc[i].DOCID; FileName = FileName.Replace(".", "_" + num.ToString() + "."); var FileStreamBytes = Request.Files[Key].InputStream; HttpPostedFileBase file = Request.Files[Key]; var DocumentNames = RequestDoc[i].DocName; DocumentCode = Context.tblMasDocuments.Where(a => a.DocumentName == DocumentNames).Select(a => a.DocumentCode).FirstOrDefault(); DepartmentCode = Context.tblMasDocuments.Where(a => a.DocumentName == DocumentNames).Select(a => a.DocumentType).FirstOrDefault(); // DepartmentCode = "UW"; if (RequestDoc[i].DocName == "SpouseImage") { DocumentCode = "PRD012"; } if (DocumentCode == null) { DocumentCode = "PRD011"; } if (file.ContentLength <= 4000000) { var ext = Path.GetExtension(FileName); string _Contact = Convert.ToString(ObjPolicy.ContactID); string _DepartmentCode = Convert.ToString(DepartmentCode); string _AgentCode = Convert.ToString(AgentCode); string _ProposalNo = Convert.ToString(ObjPolicy.ProposalNo); //string _DepartmentCode = DepartmentCode; string _DocumentCode = DocumentCode; DocumentUpload(file, FileName, _AgentCode, _ProposalNo, _DocumentCode); } else { ObjPolicy.Error.ErrorMessage = "File Size Exceeded"; return(ObjPolicy); } string directryPath = ConfigurationManager.AppSettings["FileUpload"] + "\\" + AgentCode + "\\" + ObjPolicy.ProposalNo; var exts = Path.GetExtension(FileName); exts = exts.ToLower(); if (exts == ".png" || exts == ".jpeg" || exts == ".jpg") { exts = ".pdf"; } FileName = Path.Combine(directryPath, DocumentCode + "" + exts); objUpload.FilePath = FileName; objUpload.ItemType = RequestDoc[i].ItemType; objUpload.MemberType = RequestDoc[i].MemberType; objUpload.Index = i; LstDocumentUpload.Add(objUpload); } } else { DocumentUploadFile objUpload = new DocumentUploadFile(); objUpload.FilePath = RequestDoc[i].FilePath; objUpload.FileName = RequestDoc[i].DocName; objUpload.ItemType = RequestDoc[i].ItemType; objUpload.MemberType = RequestDoc[i].MemberType; objUpload.Index = i; LstDocumentUpload.Add(objUpload); } } ObjPolicy.HdnDocumentDetails = JsonConvert.SerializeObject(LstDocumentUpload); ObjPolicy.Error.ErrorMessage = "Success"; return(ObjPolicy); } catch (Exception ex) { ObjPolicy.Error.ErrorMessage = ex.Message; return(ObjPolicy); } }
//public ActionResult SavePolicyDocuments(int ContactID, string ProposalNo , string objLstDoc, int Req = 0) //{ // try // { // AVOAIALifeEntities Context = new AVOAIALifeEntities(); // //string objLstDoc = ""; // string DepartmentCode = "", AgentCode = "", DocumentCode = ""; // if (ProposalNo == "") // { // ProposalNo = "PBBBQ123456"; // } // string UserName = User.Identity.Name; // AgentCode = Context.tblMasIMOUsers.Where(a => a.UserID == UserName).Select(a => a.AgentCode).FirstOrDefault(); // //DepartmentCode = GetMaritialStatus(); // List<DocumentUploadFile> LstDocumentUpload = new List<DocumentUploadFile>(); // List<DocumentUploadFile> RequestDoc = new List<DocumentUploadFile>(); // string FileName = ""; // Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); // RequestDoc = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DocumentUploadFile>>(objLstDoc, settings); // string StrWriteException = string.Empty; // for (var i = 0; i < RequestDoc.Count(); i++) // { // if (string.IsNullOrEmpty(RequestDoc[i].FilePath)) // { // if (Request.Files[RequestDoc[i].Key] != null) // { // string Key = RequestDoc[i].Key; // DocumentUploadFile objUpload = new DocumentUploadFile(); // Random rnd = new Random(); // int num = rnd.Next(1, 9999); // FileName = Request.Files[Key].FileName; // objUpload.FileName = RequestDoc[i].DocName; // //objUpload.DOCID = RequestDoc[i].DOCID; // FileName = FileName.Replace(".", "_" + num.ToString() + "."); // var FileStreamBytes = Request.Files[Key].InputStream; // HttpPostedFileBase file = Request.Files[Key]; // var DocumentNames = RequestDoc[i].DocName; // DocumentCode = Context.tblMasDocuments.Where(a=>a.DocumentName == DocumentNames).Select(a=>a.DocumentCode).FirstOrDefault(); // DepartmentCode = Context.tblMasDocuments.Where(a => a.DocumentName == DocumentNames).Select(a => a.DocumentType).FirstOrDefault(); // // DepartmentCode = "UW"; // if (RequestDoc[i].DocName=="SpouseImage") // { // DocumentCode = "PRD012"; // } // if(DocumentCode==null) // { // DocumentCode = "PRD011"; // } // if (file.ContentLength <= 4000000) // { // var ext = Path.GetExtension(FileName); // string _Contact = Convert.ToString(ContactID); // string _DepartmentCode = Convert.ToString(DepartmentCode); // string _AgentCode = Convert.ToString(AgentCode); // string _ProposalNo = Convert.ToString(ProposalNo); // //string _DepartmentCode = DepartmentCode; // string _DocumentCode = DocumentCode; // DocumentUpload(file, FileName, _AgentCode, _ProposalNo, _DocumentCode); // } // else // { // StrWriteException = "File Size Exceeded"; // var objResult = new { StrWriteException = StrWriteException }; // return Json(objResult, JsonRequestBehavior.AllowGet); // } // string directryPath = ConfigurationManager.AppSettings["FileUpload"] + "\\" + AgentCode + "\\" + ProposalNo; // var exts =Path.GetExtension(FileName); // exts = exts.ToLower(); // if (exts == ".png" || exts == ".jpeg" || exts == ".jpg") // { // exts = ".pdf"; // } // FileName = Path.Combine(directryPath, DocumentCode+""+exts); // objUpload.FilePath = FileName; // objUpload.ItemType = RequestDoc[i].ItemType; // objUpload.MemberType = RequestDoc[i].MemberType; // objUpload.Index = i; // LstDocumentUpload.Add(objUpload); // } // } // else // { // DocumentUploadFile objUpload = new DocumentUploadFile(); // objUpload.FilePath = RequestDoc[i].FilePath; // objUpload.FileName = RequestDoc[i].DocName; // objUpload.ItemType = RequestDoc[i].ItemType; // objUpload.MemberType = RequestDoc[i].MemberType; // objUpload.Index = i; // LstDocumentUpload.Add(objUpload); // } // } // string JsonData = JsonConvert.SerializeObject(LstDocumentUpload); // var objRes = new { DocData = JsonData, StrWriteException = StrWriteException }; // return Json(objRes, JsonRequestBehavior.AllowGet); // } // catch (Exception ex) // { // var objRes = new { StrWriteException = "Some error occured" }; // return Json(objRes, JsonRequestBehavior.AllowGet); // } //} public ActionResult SavePolicyDocuments(int ContactID, string ProposalNo, string objLstDoc, HttpPostedFileBase UploadFiles, int Req = 0) { try { string StrWriteException = string.Empty; List <DocumentUploadFile> LstDocumentUpload = new List <DocumentUploadFile>(); string JsonData = JsonConvert.SerializeObject(LstDocumentUpload); var objRes = new { DocData = JsonData, StrWriteException = StrWriteException }; return(Json(objRes, JsonRequestBehavior.AllowGet)); AVOAIALifeEntities Context = new AVOAIALifeEntities(); //string objLstDoc = ""; string DepartmentCode = "", AgentCode = "", DocumentCode = ""; if (ProposalNo == "") { ProposalNo = "PBBBQ123456"; } string UserName = User.Identity.Name; AgentCode = Context.tblMasIMOUsers.Where(a => a.UserID == UserName).Select(a => a.AgentCode).FirstOrDefault(); //DepartmentCode = GetMaritialStatus(); // List<DocumentUploadFile> LstDocumentUpload = new List<DocumentUploadFile>(); List <DocumentUploadFile> RequestDoc = new List <DocumentUploadFile>(); string FileName = ""; Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); RequestDoc = Newtonsoft.Json.JsonConvert.DeserializeObject <List <DocumentUploadFile> >(objLstDoc, settings); byte[] fileData = null; string directryPath = ConfigurationManager.AppSettings["FileUpload"] + "\\" + AgentCode + "\\" + ProposalNo; string _DepartmentCode = Convert.ToString(DepartmentCode); string _AgentCode = Convert.ToString(AgentCode); string _ProposalNo = Convert.ToString(ProposalNo); int count = 0; for (var i = 0; i < Request.Files.Count; i++) { var ReqDoc = RequestDoc.Where(a => a.Key == Request.Files.GetKey(i)).FirstOrDefault(); fileData = null; count = i; if (string.IsNullOrEmpty(ReqDoc.FilePath)) { if (Request.Files[i] != null) { string Key = RequestDoc[i].Key; DocumentUploadFile objUpload = new DocumentUploadFile(); Random rnd = new Random(); int num = rnd.Next(1, 99999); FileName = Request.Files[i].FileName; objUpload.FileName = ReqDoc.DocName; //objUpload.DOCID = RequestDoc[i].DOCID; FileName = FileName.Replace(".", "_" + num.ToString() + "."); var FileStreamBytes = Request.Files[i].InputStream; HttpPostedFileBase file = Request.Files[i]; var DocumentNames = ReqDoc.DocName; DocumentCode = Context.tblMasDocuments.Where(a => a.DocumentName == DocumentNames).Select(a => a.DocumentCode).FirstOrDefault(); DepartmentCode = Context.tblMasDocuments.Where(a => a.DocumentName == DocumentNames).Select(a => a.DocumentType).FirstOrDefault(); // DepartmentCode = "UW"; if (ReqDoc.DocName == "SpouseImage") { DocumentCode = "PRD012"; } if (DocumentCode == null) { DocumentCode = "PRD011"; } if (file.ContentLength <= 4000000) { var ext = Path.GetExtension(FileName); string _Contact = Convert.ToString(ContactID); //string _DepartmentCode = DepartmentCode; string _DocumentCode = DocumentCode; fileData = DocumentUpload(file, FileName, _AgentCode, _ProposalNo, _DocumentCode, null, "Proposal"); } else { StrWriteException = "File Size Exceeded"; var objResult = new { StrWriteException = StrWriteException }; return(Json(objResult, JsonRequestBehavior.AllowGet)); } var exts = Path.GetExtension(FileName); exts = exts.ToLower(); if (exts == ".png" || exts == ".jpeg" || exts == ".jpg") { exts = ".pdf"; } var names = FileName.Split('.'); var number = names[0].Split('_'); var nums = number[1]; FileName = Path.Combine(directryPath, DocumentCode + "_" + nums + "" + exts); objUpload.FilePath = FileName; objUpload.ItemType = ReqDoc.ItemType; objUpload.MemberType = ReqDoc.MemberType; objUpload.FileData = fileData; objUpload.Index = i; objUpload.DOCID = ReqDoc.DOCID; LstDocumentUpload.Add(objUpload); } } else { DocumentUploadFile objUpload = new DocumentUploadFile(); objUpload.FilePath = ReqDoc.FilePath; objUpload.FileName = ReqDoc.DocName; objUpload.ItemType = ReqDoc.ItemType; objUpload.MemberType = ReqDoc.MemberType; objUpload.FileData = fileData; objUpload.Index = i; objUpload.DOCID = ReqDoc.DOCID; LstDocumentUpload.Add(objUpload); } } foreach (var obj in RequestDoc.Where(a => a.FileName == "")) { DocumentUploadFile objUpload = new DocumentUploadFile(); objUpload.FilePath = null; objUpload.FileName = obj.DocName; objUpload.ItemType = obj.ItemType; objUpload.MemberType = obj.MemberType; objUpload.FileData = null; objUpload.Index = count; objUpload.DOCID = obj.DOCID; LstDocumentUpload.Add(objUpload); count++; } byte[] ConcatFiles; directryPath = ConfigurationManager.AppSettings["FileUpload"] + "\\" + AgentCode + "\\" + ProposalNo + "\\LDMS"; if (!Directory.Exists(directryPath)) { Directory.CreateDirectory(directryPath); } var PolicyID = Context.tblPolicies.Where(a => a.ProposalNo == ProposalNo).Select(a => a.PolicyID).FirstOrDefault(); var RecievedFiles = Context.tblPolicyDocuments.Where(a => a.PolicyID == PolicyID && a.Decision == "2370").ToList(); List <DocumentUploadFile> LstTotalFiles = new List <DocumentUploadFile>(); foreach (var item in RecievedFiles) { DocumentUploadFile objDoc = new DocumentUploadFile(); objDoc.FileName = item.FileName; objDoc.FilePath = item.FilePath; objDoc.FileData = GetFile(item.FilePath); if (objDoc.FileData != null) { LstTotalFiles.Add(objDoc); } } foreach (var fName in LstDocumentUpload.Where(a => a.FilePath != null).Concat(LstTotalFiles).Select(a => a.FileName).Distinct().ToList()) { ConcatFiles = CrossCutting.DataTypeConvExtention.ConcatPdf(LstDocumentUpload.Where(a => a.FileName == fName && a.FilePath != null).Concat(LstTotalFiles.Where(a => a.FileName == fName)).Select(a => a.FileData).ToList()); DocumentCode = Context.tblMasDocuments.Where(a => a.DocumentName == fName).Select(a => a.DocumentCode).FirstOrDefault(); System.IO.File.WriteAllBytes(directryPath + "\\" + DocumentCode + ".pdf", ConcatFiles); } foreach (var objUpload in LstDocumentUpload) { objUpload.FileData = null; } // string JsonData = JsonConvert.SerializeObject(LstDocumentUpload); // var objRes = new { DocData = JsonData, StrWriteException = StrWriteException }; return(Json(objRes, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var objRes = new { StrWriteException = "Some error occured" }; return(Json(objRes, JsonRequestBehavior.AllowGet)); } }
public string FileUpload(DomFile obj) { string Result = ""; try { if (!string.IsNullOrEmpty(obj.Agent_Code) && !string.IsNullOrEmpty(obj.Policy_No) && !string.IsNullOrEmpty(obj.FileName)) { //string zipPath = @"E:\AIA\test1.zip"; byte[] FileBytes = Convert.FromBase64String(obj.Filedata); //System.IO.File.ReadAllBytes(zipPath); // string Path = ConfigurationManager.AppSettings["DocumentUploadPath"]; //@"E:\AIA\uploaddocsmobility"; //bool IsfolderExist = CheckImageExist(obj.Department_Code); //if (IsfolderExist == false) //{ // var directoryInfo1 = new DirectoryInfo(Path); // directoryInfo1.CreateSubdirectory(obj.Department_Code); //} //Path = Path + @"\" + obj.Department_Code; bool IsfolderExist = CheckImageExist(obj.Agent_Code); if (IsfolderExist == false) { var directoryInfo1 = new DirectoryInfo(Path); directoryInfo1.CreateSubdirectory(obj.Agent_Code); } Path = Path + "//" + obj.Agent_Code; IsfolderExist = CheckImageExist(obj.Agent_Code + @"\" + obj.Policy_No); if (IsfolderExist == false) { var directoryInfo1 = new DirectoryInfo(Path); directoryInfo1.CreateSubdirectory(obj.Policy_No); } Path = Path + @"\" + obj.Policy_No; string zipPath1 = ConfigurationManager.AppSettings["DocumentUploadZipPath"]; Random rnd = new Random(); obj.FileName = rnd.Next(1, 9999) + obj.FileName; bool isExist = System.IO.File.Exists(zipPath1 + obj.FileName); FileStream fs = new FileStream(zipPath1 + obj.FileName, FileMode.Append); if (FileBytes.Count() > 0) { fs.Write(FileBytes, 0, FileBytes.Length); } fs.Close(); #region File validations using (ZipFile zip = ZipFile.Read(zipPath1 + obj.FileName)) { foreach (ZipEntry e in zip) { try { using (var stream = e.OpenReader()) { if (!ValidateFileType.IsAllowedFileType(e.FileName, (Stream)stream)) { Result = "Please Provide Valid File Format"; return(Result); } } } catch (Exception ex) { } } } #endregion #region Convert to PDF List <DocumentUploadFile> LstDocumentUpload = new List <DocumentUploadFile>(); UtilityController objUtilityController = new UtilityController(); using (ZipFile zip = ZipFile.Read(zipPath1 + obj.FileName)) { foreach (ZipEntry e in zip) { try { using (var stream = e.OpenReader()) { DocumentUploadFile objUpload = new DocumentUploadFile(); MemoryStream ms = new MemoryStream(); e.Extract(ms); byte[] bytes = new byte[ms.Length]; bytes = objUtilityController.PdfGeneration(ms.ToArray()); System.IO.File.WriteAllBytes(Path + "//" + e.FileName.Substring(0, e.FileName.IndexOf(".")) + ".pdf", bytes); objUpload.FileName = e.FileName.Split('.')[0].Split('_')[0]; objUpload.FileData = bytes; LstDocumentUpload.Add(objUpload); } //DocumentUploadFile objUpload = new DocumentUploadFile(); //objUpload.FilePath = obj.FileName;.spli //objUpload.ItemType = RequestDoc[i].ItemType; //objUpload.MemberType = RequestDoc[i].MemberType; //objUpload.FileData = fileData; } catch (Exception ex) { } } } byte[] ConcatFiles; var directryPath = ConfigurationManager.AppSettings["FileUpload"] + "\\" + obj.Agent_Code + "\\" + obj.Policy_No + "\\LDMS"; if (!Directory.Exists(directryPath)) { Directory.CreateDirectory(directryPath); } foreach (var fName in LstDocumentUpload.Select(a => a.FileName).Distinct().ToList()) { ConcatFiles = CrossCutting.DataTypeConvExtention.ConcatPdf(LstDocumentUpload.Where(a => a.FileName == fName).Select(a => a.FileData).ToList()); //System.IO.File.WriteAllBytes(ConfigurationManager.AppSettings["LDMSFileUpload"] + "\\" + obj.Agent_Code + "\\" + obj.Policy_No + "\\" + fName + ".pdf", ConcatFiles); System.IO.File.WriteAllBytes(directryPath + "\\" + fName + ".pdf", ConcatFiles); } #endregion //ZipFile fileToExtract = ZipFile.Read(zipPath1 + obj.FileName); //fileToExtract.ExtractAll(Path, ExtractExistingFileAction.DoNotOverwrite); Result = Path; } else { Result = "Kindly provide Department code, Agent Code, Document Name and policy number to proceed..!"; } } catch (Exception ex) { log4net.GlobalContext.Properties["ErrorCode"] = Codes.GetErrorCode(); Logger.Error(ex); Result = "Failure"; } return(Result); }
public ActionResult saveAppointmentfiles(int AppointmentID, string objLstDoc, int Req = 0) { try { List <DocumentUploadFile> LstDocumentUpload = new List <DocumentUploadFile>(); List <DocumentUploadFile> RequestDoc = new List <DocumentUploadFile>(); string FileName = ""; Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); RequestDoc = Newtonsoft.Json.JsonConvert.DeserializeObject <List <DocumentUploadFile> >(objLstDoc, settings); string StrWriteException = string.Empty; for (var i = 0; i < RequestDoc.Count(); i++) { if (string.IsNullOrEmpty(RequestDoc[i].FilePath)) { if (Request.Files[RequestDoc[i].Key] != null) { string Key = RequestDoc[i].Key; DocumentUploadFile objUpload = new DocumentUploadFile(); Random rnd = new Random(); int num = rnd.Next(1, 9999); FileName = Request.Files[Key].FileName; objUpload.FileName = RequestDoc[i].DocName; FileName = FileName.Replace(".", "_" + num.ToString() + "."); var FileStreamBytes = Request.Files[Key].InputStream; HttpPostedFileBase file = Request.Files[Key]; if (file.ContentLength <= 1000000) { var ext = Path.GetExtension(FileName); DocumentUpload(file, FileName); } else { StrWriteException = "File Size Exceeded"; var objResult = new { StrWriteException = StrWriteException }; return(Json(objResult, JsonRequestBehavior.AllowGet)); } string directryPath = Server.MapPath("AppointmentID_" + AppointmentID); FileName = Path.Combine(directryPath, FileName); objUpload.FilePath = FileName; objUpload.ItemType = RequestDoc[i].ItemType; objUpload.Index = i; LstDocumentUpload.Add(objUpload); } } else { DocumentUploadFile objUpload = new DocumentUploadFile(); objUpload.FilePath = RequestDoc[i].FilePath; objUpload.FileName = RequestDoc[i].DocName; objUpload.ItemType = RequestDoc[i].ItemType; objUpload.Index = i; LstDocumentUpload.Add(objUpload); } } string JsonData = JsonConvert.SerializeObject(LstDocumentUpload); ViewBag.UploadStatus = JsonData; var objRes = new { DocData = JsonData, StrWriteException = StrWriteException }; return(Json(objRes, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var objRes = new { StrWriteException = "Some error occured" }; return(Json(objRes, JsonRequestBehavior.AllowGet)); } }