I want to show members and owners in a webpart. My site collection can be created in different languages, so I can't get needed groups like web.Groups["Contoso Members"]. Because it may be "Medlemmar på Contoso" or something else.

When I ran $web.Groups I saw Members group had id 5.

Can I trust this id number? Or is it random number?

SPGroup members = web.Groups[5]
foreach (SPUser user in members.Users)
   //show it

You can't count on that number, as it's just the index within the collection.

The AssociatedMemberGroup and AssociatedOwnerGroup properties on SPWeb should give you what you're looking for without having to know the actual name of the group.

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.