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 have an SPGroup object populated, how can I remove all members from the group, so that essentially I start with a fresh group.

I can't delete and recreate it, so I need a way to work with the existing SharePoint group.

Thanks in advance

share|improve this question

1 Answer 1

up vote 7 down vote accepted

Take a look on msdn

    foreach (SPUser user in group.Users)
    {
        group.RemoveUser(user);
    }

But be aware that you change this group for the whole site collection, if you have other site collections those won't be impacted by the modification of this group.

share|improve this answer
1  
Won't this throw a modify collection exception? –  JL01 Sep 16 '11 at 11:55
    
I have tested it and it works. –  Anatoly Mironov Sep 16 '11 at 12:18
1  
Neat, was looking for this. I was afraid that this would in fact skip every other user due to the indexes changing as users get removed, as is the situation when removing groups for example. Tried it, and it worked fine. Nice solution Anatoly. =) –  Johannes Jan 31 '12 at 16:12

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.