I am working with updating groups programmatically and have been wondering how SPGroup's react when you:

a) Try to remove people that are not already a member - silently fail, throw exception, ??
b) Try to add a person to a group he is already a member of - again, with what outcome.

Since MSDN do not document Exception-handling (at all) I tried google but I can't seem to find any articles with my google-fu that will give me the right answer.

Any and all help is appreciated.

  • 5
    Why don't you test it yourself? – tarjeieo Jun 3 '11 at 13:23
  • I agree that it would be helpful for MSDN to include more information on expections for SharePoint. However, I think you have to test it to find out. Have you tried using Powershell for quick tests? I find it very helpful for small things like this. – Tom Resing Jun 3 '11 at 22:07

In both cases nothing will happen because there is nothing to do on SPGroup.Update(). If you are trying to add user that already exist - it's already there and if you are trying to remove user who is not member of group - there is nothing to remove.

Your code will continue as normal and no exception will be thrown.

I personally find this 'malfunction' to be very useful especially in case where you are programmatically doing bulk SPGroup updates.


I can only provide anacdotal evidence to this question. In some Nintex workflows we have, we are adding users to groups via the web services. When a user is already in the group, the workflow continues on, the workflow does not error. I haven't tried to decipher if it is readding the user or if it is just aborting and silently continuing because the user is there.

I have not tried to remove users from a group via the web services in a workflow so I don't have any evidence to give you on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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