private void DeleteChildren(File file)
        {
            //delete ALL children items where user has delete permission

            FileController fileCtrl = new FileController();
            List<File> files = fileCtrl.GetItems(file.ID) as List<File>;
            foreach (File childFile in files)
            {
                if (file.ItemType == 0)
                {
                    DeleteChildren(childFile);
                }
            }
                //send to trash if not folder
                if (file.ItemType != 0 && file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //send to trash if not there already
                    if (!file.IsInTrash)
                    {
                        file.IsInTrash = true;
                        fileCtrl.Update(file);
                        #region "Audit"
                        //Audit: Create Item
                        AuditController ctrlAudit = new AuditController();
                        Audit deleteAudit = new Audit() { EventDate = file.LastModifiedDate, EventDetails = "", EventName = "Deleted", FileID = file.ID, UserID = UserId };
                        ctrlAudit.Create(deleteAudit);
                        #endregion
                        _deletedFilesCount++;
                        return;
                    }

                    //if file is in trash, delete permissions and file
                    if (file.IsInTrash)
                    {
                        PermissionController permCtrl = new PermissionController();

                        //delete versions and version permissions
                        List<File> versions = fileCtrl.GetItems(file.ID) as List<File>;
                        foreach (File version in versions)
                        {
                            List<Permission> versionPermissions = permCtrl.GetItems(version.ID) as List<Permission>;
                            for (int i = 0; versionPermissions.Count - 1 > i; i++)
                            {
                                permCtrl.Delete(versionPermissions[i]);
                            }
                            fileCtrl.Delete(version);
                        }

                        //delete file permissions
                        List<Permission> folderPermissions = permCtrl.GetItems(file.ID) as List<Permission>;
                        for (int i = 0; folderPermissions.Count - 1 >= i; i++)
                        {
                            permCtrl.Delete(folderPermissions[i]);
                        }

                        //delete file instead of sending to trash
                        _filesToDelete.Add(file);
                        //fileCtrl.Delete(file);

                        _permanentlyDeletedFilesCount++;
                        return;
                    }
                }

                //check if any items exist under folder and delete permission before deleting
                if (file.ItemType == 0 && file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //get current child count
                    List<File> childFiles = fileCtrl.GetItems(file.ID) as List<File>;
                    int childFilesCount = 0;

                    //count child items not in trash
                    foreach (File childFileCount in childFiles)
                    {
                        if (!childFileCount.IsInTrash)
                        {
                            childFilesCount++;
                        }
                    }

                    //no child items, permanently delete folder
                    if (childFilesCount == 0)
                    {
                        //delete folder permissions
                        PermissionController permCtrl = new PermissionController();
                        List<Permission> folderPermissions = permCtrl.GetItems(file.ID) as List<Permission>;
                        for (int i = 0; folderPermissions.Count - 1 >=  i; i++)
                        {
                            permCtrl.Delete(folderPermissions[i]);
                        }

                        //delete folder instead of sending to trash
                        _filesToDelete.Add(file);
                        //fileCtrl.Delete(file);

                        _deletedFilesCount++;
                        return;
                    }
                    else
                    {
                        _notDeletedFilesCount++;
                        return;
                    }
                }
                _notDeletedFilesCount++;
        }
        private void ApplyPermissions(File file)
        {
            string strMyPermission = "";

            //check if in trash, lock down changes
            if (file.IsInTrash)
            {
                //disable edit controls
                txtDescription.Enabled = false;
                txtName.Enabled = false;
                txtVersionsToKeep.Enabled = false;
                lbnDeleteVersions.Visible = false;
                linkAddVersion.Visible = false;
                lbnOK.Visible = false;

                //disable permission controls
                lbnAddUser.Visible = false;
                txtUser.Visible = false;
                lblUser.Visible = false;
                gridPermissions.Enabled = false;
            }

            //see
            if (!file.CanSee(UserId, PortalId, PortalSettings.AdministratorRoleId, true))
            {
                Response.Redirect(Globals.NavigateURL());
            }
            else
            {
                strMyPermission = "See, ";
            }

            //add items
            if (file.CanAddFile(UserId, PortalId, PortalSettings.AdministratorRoleId, true))
            {
                strMyPermission = strMyPermission + "Add Items, ";
            }

            //add folders
            if (file.CanAddFolder(UserId, PortalId, PortalSettings.AdministratorRoleId, true))
            {
                strMyPermission = strMyPermission + "Add Folders, ";
            }

            //modify
            if (!file.CanModify(UserId, PortalId, PortalSettings.AdministratorRoleId, true))
            {
                //disable edit controls
                txtDescription.Enabled = false;
                txtName.Enabled = false;
                txtVersionsToKeep.Enabled = false;
                txtHyperlink.Enabled = false;
                lbnDeleteVersions.Visible = false;
                linkAddVersion.Visible = false;
                lbnOK.Visible = false;
            }
            else
            {
                strMyPermission = strMyPermission + "Modify, ";
            }

            //delete
            if (!file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, true))
            {
                this.linkDelete.Visible = false;
            }
            else
            {
                strMyPermission = strMyPermission + "Delete, ";
            }

            //edit permission
            if (!file.CanEditPermissions(UserId, PortalId, PortalSettings.AdministratorRoleId, true))
            {
                gridPermissions.Visible = false;
                txtUser.Visible = false;
                lblPermissionsGrid.Visible = false;
                lblUser.Visible = false;
                lbnAddUser.Visible = false;
                ApplyPermissionToSubItems.Visible = false;
            }
            else
            {
                strMyPermission = strMyPermission + "Edit Permissions, ";
                if (file.ItemType != 0)
                {
                    ApplyPermissionToSubItems.Visible = false;
                }
            }

            lblMyPermissions.Text = strMyPermission.Substring(0, strMyPermission.Length - 2);

            //remove versions for folder and hyperlink regardless
            if (file.ItemType == 0 || file.ItemType == 2)
            {
                lbnDeleteVersions.Visible = false;
                linkAddVersion.Visible = false;
                txtVersionsToKeep.Visible = false;
                lblVersionCount.Visible = false;
                liVersions.Visible = false;
                lblVersionToKeepLabel.Visible = false;
                lblVersionCountLabel.Visible = false;
                gridVersions.Visible = false;
            }
        }