Reputation: 13
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..
Upvotes: 1
Views: 624
Reputation: 6988
SPFarm farm = SPFarm.Local;
farm.CurrentUserIsAdministrator();
These classes reside in Microsoft.SharePoint.Administration namespace. More on CurrentUserIsAdministrator or SPFarm class on MSDN.
Upvotes: 1
Reputation: 1
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;
}
Upvotes: 0