public static void SynchronizeFolder(int PortalId, string physicalPath, string relativePath, bool isRecursive, bool syncFiles, bool forceFolderSync, bool hideSystemFolders)
 {
     CommonLibrary.Services.FileSystem.FolderController objFolderController = new CommonLibrary.Services.FileSystem.FolderController();
     int FolderId;
     bool isInSync = true;
     if (forceFolderSync == true && String.IsNullOrEmpty(relativePath))
     {
         RemoveOrphanedFolders(PortalId);
     }
     CommonLibrary.Services.FileSystem.FolderInfo folder = objFolderController.GetFolder(PortalId, relativePath, false);
     DirectoryInfo dirInfo = new DirectoryInfo(physicalPath);
     if (dirInfo.Exists)
     {
         if (folder == null)
         {
             if (ShouldSyncFolder(hideSystemFolders, dirInfo))
             {
                 FolderId = AddFolder(PortalId, relativePath, (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem);
                 folder = objFolderController.GetFolder(PortalId, relativePath, true);
                 isInSync = false;
             }
             else
             {
                 //Prevent further processing of this folder
                 return;
             }
         }
         else
         {
             isInSync = (dirInfo.LastWriteTime.ToString("yyyyMMddhhmmss") == folder.LastUpdated.ToString("yyyyMMddhhmmss"));
         }
         if (folder != null)
         {
             if (syncFiles == true && (isInSync == false || forceFolderSync == true))
             {
                 string[] strFiles = Directory.GetFiles(physicalPath);
                 foreach (string strFileName in strFiles)
                 {
                     AddFile(strFileName, PortalId, false, folder);
                 }
                 RemoveOrphanedFiles(folder, PortalId);
                 folder.LastUpdated = dirInfo.LastWriteTime;
                 objFolderController.UpdateFolder(folder);
             }
             if (isRecursive)
             {
                 string[] strFolders = Directory.GetDirectories(physicalPath);
                 foreach (string strFolder in strFolders)
                 {
                     DirectoryInfo dir = new DirectoryInfo(strFolder);
                     string relPath = Null.NullString;
                     if (String.IsNullOrEmpty(relativePath))
                     {
                         relPath = dir.Name + "/";
                     }
                     else
                     {
                         relPath = relativePath;
                         if (!relativePath.EndsWith("/"))
                         {
                             relPath = relPath + "/";
                         }
                         relPath = relPath + dir.Name + "/";
                     }
                     SynchronizeFolder(PortalId, strFolder, relPath, true, syncFiles, forceFolderSync, hideSystemFolders);
                 }
             }
         }
     }
     else
     {
         if (folder != null)
         {
             if (folder.StorageLocation != (int)CommonLibrary.Services.FileSystem.FolderController.StorageLocationTypes.DatabaseSecure)
             {
                 RemoveOrphanedFiles(folder, PortalId);
                 objFolderController.DeleteFolder(PortalId, relativePath.Replace("\\", "/"));
             }
         }
     }
 }