Question

I am developing a sharepoint feature that should allow only Farm admin to delete a sitecollection. In SiteDeleting event, i need to chech if the user deleting is farmadmin. How should i do that? I got a property to check if user is webadmin(properties.Web.UserIsWebAdmin) or siteadmin(properties.Web.UserIsSiteAdmin) but how to check if the user is farm admin ?

Any help is much appreciated..

Was it helpful?

Solution

SPFarm farm = SPFarm.Local;
farm.CurrentUserIsAdministrator();

These classes reside in Microsoft.SharePoint.Administration namespace. More on CurrentUserIsAdministrator or SPFarm class on MSDN.

OTHER TIPS

public static bool IsFarmAdmin(string loginName)
            {
                //For Currently Logged in users  
                //SPFarm.Local.CurrentUserIsAdministrator();  

        bool isFarmAdmin = false;

        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            SPGroup adminGroup = SPAdministrationWebApplication.Local.Sites[0].AllWebs[0].SiteGroups["Farm Administrators"];

            foreach (SPUser user in adminGroup.Users)
            {
                if (user.LoginName == loginName)
                {
                    isFarmAdmin = true;
                }
            }

        });

        return isFarmAdmin;
    } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top