Following code adds user to SP Group. This code works perfectly and adding user to group. But permission is not going to set for the user from the group. When I go to site and "Check Permissions" user is not given permission from the added SP Group. Can anyone guess what goes wrong?
ClientContext client = new ClientContext("SiteURL");
client.ExecuteQuery();
Web website = client.Web;
client.Load(website, w => w.AllProperties, w => w.SiteGroups, w => w.SiteUserInfoList, w => w.Webs,w => w.Title);
client.ExecuteQuery();
GroupCollection groupCollection = website.SiteGroups;
client.Load(groupCollection, groups => groups.Include(grps => grps.Users, grps => grps.Title));
client.ExecuteQuery();
User user;
foreach (Group group in groupCollection)
{
if (group.Title.Equals("test Members"))
{
UserCreationInformation userInfo = new UserCreationInformation();
userInfo.LoginName = @"mydomain\user";
user = group.Users.Add(userInfo);
group.Users.AddUser(user);
group.Update();
website.Update();
client.ExecuteQuery();
}
}