Tuesday, October 22, 2013

How to check if a user belongs to a SharePoint Group or Not ?

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

Rename a Web Application in Sharepoint : A solution using powershell

Here is a small script that will enable you all to change a SharePoint Web Application name . We can use the following SharePoint Pow...