bool flag=false;
SPSite site = SPContext.Current.Site;
using (SPWeb web = site.OpenWeb())
{
SPUser currentUser = web.EnsureUser("Domain\UserLogin");
SPGroupCollection userGroups = currentUser.Groups;
foreach (SPGroup group in userGroups)
{
if (group.Name.Contains("SharePoint Group Name"))
{
//User belongs to the group
flag=true;
break;
}
}
}
if(flag==false)
{
//Add user to the group
}
I have not tested this, please check for any build errors and test, if it suits your needs..
Ram Prasad Meenavalli | MCITP | MCTS SharePoint | MCPD SharePoint | http://ift.tt/1iDFivl
No comments:
Post a Comment