How to check if a user belongs to a SharePoint Group or Not ?
Well.. its not a big deal these days ..We have one liner functions to do the same in server object model.. so.. just use it ..
The method is called as IsCurrentUserMemberOfGroup(GroupName) - it returns a true if the user is present in the Group else it returns a false .. Here is the sample code for the same....
private bool IsMember()
{
bool isMember;
SPSite site = new SPSite(SiteURL);
SPWeb web = site.OpenWeb();
//Returns true on successfull membership
isMember = web.IsCurrentUserMemberOfGroup(web.Groups["GroupName"].ID);
web.Close();
site.Close();
return isMember;
}
Happy SharePointing ....
No comments:
Post a Comment