I’m trying to get one user group in SP 2010. I currently have five groups but SPGroupCollection only contains two when i read the groups with oSPWeb.Groups. Anyone know if there is any security or other reason for this?
Code:
using (SPSite oSPsite = new SPSite(_serverUrl))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
SPGroup spGroup = oSPWeb.Groups["AIT Owners"];
}
}
Yes, there is a security reason. The Groups property will only return groups that have assigned permissions within the website, while the SiteGroups property returns all groups within the site collection.
For more information, there are a number of blog articles that cover the difference.