I have different users in various sharepoint groups(Admin,User,Approver) in my site collection.Now in my visual webpart how can I validate users(from these above groups) who are going to login.
Help required.
thanks.
I have different users in various sharepoint groups(Admin,User,Approver) in my site collection.Now in my visual webpart how can I validate users(from these above groups) who are going to login. Help required. thanks. |
|||||
|
You can explore the SPGroup object. Grab the group from the web.SiteGroups["Group Name"], and then call method group.ExplicitlyContainsCurrentUser(), which will check if the current user is in the group. This won't work if you're using AD groups however. Instead, you'll need to get group.Users and iterate through, finding the AD groups (that appear as SPUser objects, yes, really), then query AD to find out if the user is in the group. There's a few ways to do that, search online for loads of examples. HTH |
|||
|
You can use the IsCurrentUserMemberOfGroup() method on the SPWeb object:
Although, since according to your comment above, the reason you want this information is to hide controls form certain users, you may be able to use the SPSecurityTrimmedControl to hide the controls based on permission levels rather than group membership. And... after a quick search to find some informative blog posts that might explain how to use the Security Trimmed Control, I actually found one that gives instructions on how to extend it to support groups. So there you go. |
|||
|