public static string RecurseThroughDirectory(DirectoryInfo dir, int folderId, int UserModuleID, ref StringBuilder sb)
    {
        foreach (FileInfo file in dir.GetFiles())
        {
            ATTFile obj = new ATTFile();
            obj.PortalId        = fb.GetPortalID;
            obj.UniqueId        = Guid.NewGuid();
            obj.VersionGuid     = Guid.NewGuid();
            obj.FileName        = file.Name;
            obj.Extension       = file.Extension;
            obj.Size            = int.Parse(file.Length.ToString());
            obj.ContentType     = FileManagerHelper.ReturnExtension(file.Extension);
            obj.Folder          = FileManagerHelper.ReplaceBackSlash(dir.FullName.Replace(HttpContext.Current.Request.PhysicalApplicationPath, ""));
            obj.FolderId        = folderId;
            obj.IsActive        = 1;
            obj.StorageLocation = 0;
            obj.AddedBy         = fb.GetUsername;

            try
            {
                if (FileManagerHelper.CheckForValidExtensions(UserModuleID, file.Extension.Replace(".", ""), fb.GetPortalID))
                {
                    FileManagerController.AddFile(obj);
                    sb.Append("File ").Append("Extraction completed successfully");
                }
                else
                {
                    sb.Append("File ").Append(file.Name).Append(" has invalid extension \n");
                }
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
        }
        foreach (DirectoryInfo childDir in dir.GetDirectories())
        {
            Folder folder = new Folder();
            folder.PortalId        = fb.GetPortalID;
            folder.ParentID        = folderId;
            folder.FolderPath      = FileManagerHelper.ReplaceBackSlash(childDir.FullName.Replace(HttpContext.Current.Request.PhysicalApplicationPath, ""));
            folder.StorageLocation = 0;
            folder.UniqueId        = Guid.NewGuid();
            folder.VersionGuid     = Guid.NewGuid();
            folder.IsActive        = 1;
            folder.IsRoot          = false;
            folder.AddedBy         = fb.GetUsername;
            try
            {
                int FolderID = FileManagerController.AddFolderReturnFolderID(folder);
                RecurseThroughDirectory(childDir, FolderID, UserModuleID, ref sb);
            }
            catch (Exception ex)
            {
                fb.ProcessException(ex);
            }
        }
        return(sb.ToString());
    }
    public static string UnzipFiles(string FilePath, int FolderID, int portalID, string userName, int userModuleID, string secureToken)
    {
        StringBuilder       sb         = new StringBuilder();
        AuthenticateService objService = new AuthenticateService();

        if (objService.IsPostAuthenticatedView(portalID, userModuleID, userName, secureToken))
        {
            string        absolutePath  = GetAbsolutePath(FilePath);
            FileInfo      file          = new FileInfo(absolutePath);
            string        folderName    = file.Name;
            string        newFolderPath = FileManagerHelper.GetFilePathWithoutExtension(absolutePath);
            DirectoryInfo dir           = new DirectoryInfo(newFolderPath);
            if (!dir.Exists)
            {
                string path = string.Empty;
                FileManagerHelper.UnZipFiles(absolutePath, newFolderPath, ref path, SageFrame.Common.RegisterModule.Common.Password, false, userModuleID, fb.GetPortalID);
                Folder folder = new Folder();
                folder.PortalId        = fb.GetPortalID;
                folder.ParentID        = FolderID;
                folder.FolderPath      = FileManagerHelper.ReplaceBackSlash(FileManagerHelper.GetFilePathWithoutExtension(FilePath));
                folder.StorageLocation = 0;
                folder.UniqueId        = Guid.NewGuid();
                folder.VersionGuid     = Guid.NewGuid();
                folder.IsActive        = 1;
                folder.IsRoot          = false;
                folder.AddedBy         = fb.GetUsername;
                try
                {
                    int folderID = FileManagerController.AddFolderReturnFolderID(folder);
                    RecurseThroughDirectory(dir, folderID, userModuleID, ref sb);
                }
                catch (Exception ex)
                {
                    fb.ProcessException(ex);
                }
            }
            CacheHelper.Clear("FileManagerFileList");
            CacheHelper.Clear("FileManagerFolders");
        }
        return(sb.ToString());
    }