only My site

Monday, August 20, 2012

SharePoint : EnsureUser & Add user to a Group


The ensureuser method adds the
string loginName = "Domain\User_Alias";
string grpName = "Group1";
//EnsureUser - Checks whether the specified logon name belongs to a valid user of the website, and if the logon name does not already exist, adds it to the website.
SPUser user = SPContext.Current.Web.EnsureUser(loginName);

SPGroup group = SPContext.Current.Web.Groups[grpName];
//Add the user to the Group
group.AddUser(user);
group.Update();

3 comments:

Unknown said...

Thanks a lot for this post

Unknown said...

Thanks a Lot fot his post

Unknown said...

Thanks a lot for this