SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I create a new group using the web interface, I'm able to use web.Groups["name of group"] to find the group.

When I create a group programatically, I use web.SiteGroups.Add("name of group", etc). But then in my code, web.Groups["name of group"] can't find the group I just created. web.SiteGroups["name of group"] does though.

My questions are:

Why is their a difference when you create the group using the web interface and when you use code to do it?

Should I always be using SiteGroups to find my groups?


share|improve this question

SPWeb.SiteGroups "Gets a collection that contains all the groups in the site collection."

That's different to SPWeb.Groups which, like you have seen, is where the web interface creates them as it's for all the groups in the site collection the current SPWeb is in. The web interface adds them to just the current SPWeb.

The good news is, you can create groups with web.Groups.Add("name of group", etc).

share|improve this answer
Thank you SPDuFeu. – DrZ Mar 26 '13 at 11:26
When I tried to add to the Groups column, I received the following error. You cannot add a group directly to the Groups collection. You can add a group to the SiteGroups collection. That's probably why I used SiteGroups. – DrZ Mar 26 '13 at 14:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.