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

share|improve this question
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
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
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.