Exemple #1
0
        public string FileUpload(DomFile obj)
        {
            string Result = "";

            try
            {
                if (!string.IsNullOrEmpty(obj.Department_Code) && !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;
                    IsfolderExist = CheckImageExist(obj.Department_Code + "//" + obj.Agent_Code);
                    if (IsfolderExist == false)
                    {
                        var directoryInfo1 = new DirectoryInfo(Path);
                        directoryInfo1.CreateSubdirectory(obj.Agent_Code);
                    }
                    Path          = Path + "//" + obj.Agent_Code;
                    IsfolderExist = CheckImageExist(obj.Department_Code + "//" + 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();
                    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);
        }
Exemple #2
0
        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);
        }