I am trying to create a new SharePoint group programmatically (using .Net), for this I am using the following C# code
//greate group with no users: web.SiteGroups.Add(groupName, groupOwner, null, description); //Parameters are defined earlier in the code such as: // string groupName // SPUser groupOwner // string description web.Update(); SPGroup newGroup = web.Groups.GetByName(groupName);
The creation works well but when I try to access the group an exception is thrown saying "Group cannot be found." What is the reason that the group can not be found and how can I fix this (I need to access the group for my further code)? If I check on the SharePoint under People and Groups the group is there.
Any help is appreciated, thanks.