1

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?

Thanks

1 Answer 1

1

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).

1
  • 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, 2013 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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