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

I need to know all groups in my site collection... If I use

  using (SPSite scSite = new SPSite(fullsite))
                {
                    using (SPWeb scWeb = scSite.OpenWeb())
                    {
                        foreach(SPGroup spg in scWeb.Groups)
                        {
                            debug += spg.Name + "!!!";
                        }
                    }
                }

The only group I get are groups which have Permissions on the site... How can I get also the groups that has no permission on the site but exists (and has permission in subsites)? There is an easy way or I have to loop on childs and get new groups from there??

Thank you very much!

share|improve this question
    
What's wrong with just going to /_layouts/groups.aspx on your rootweb? It lists all groups existing on your site –  Daniel Ziga Feb 7 '12 at 12:56
    
Programmatically =/ So i must use the SP Api! –  Ziba Leah Feb 7 '12 at 13:50

2 Answers 2

up vote 3 down vote accepted

You need SPWeb.SiteGroups (MSDN link) which includes all groups that exist in the site collection.

For further details, please refer to: http://blog.tylerholmes.com/2007/09/spwebgroups-vs-spwebsitegroups.html

share|improve this answer

Have a look at this article.

Programmatically get SharePoint Users with Group Name

Hope this helps You!

share|improve this answer
    
We require relevant answers and disclosure of any affiliation with products or websites. Please see May I promote products or websites I am affiliated with here? for guidelines. –  SPDoctor May 9 '12 at 15:21

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.