Wednesday, May 28, 2008

How to know if user is a member of specific group?

Hi All,

Sometimes we may require to know if current logged-in user is a member of any specific group or not?

Here is a simple way to accomplish this. But just make sure that user under which the code is running is having sufficient rights to access the groups in web.

Becuase make sure that the code that runs under ElevatedPrivileges will be running under system account and you will never be able to take the current user in that code.

if ( web.Groups["Group_Name"].ContainsCurrentUser )
{
// code implementation
}

This condition simple checks if the user is in specific group or not.

That's it. Your job is done.

No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com