Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.