How can I find out programmatically if current user belongs to some group on sharepoint website?
I need it because I would like to show a different content for the users belonging to one group.
views:
1150answers:
5Hi agnieszka,
maybe this code sample post in the ASP.NET Forums helps.
A method you could use
/// <summary>
/// This private method get users by selected SPGroup object.
/// </summary>
/// <param name="group">SPGroup object</param>
private void UsersList(SPGroup group)
{
foreach(SPUser singleUser in group.Users)
{
foreach(SPRole singleRole in singleUser.Roles)
{
_usersListCollection.Add(new UserListCollection(
singleUser.LoginName,singleRole.Name,group.ParentWeb.Title));
}
}
}
Good luck,
Henrik
Hi,
One way to approach that kind of issues is to find inspiration at Codeplex. The quality of the code that people have released is usually very good.
I am sure that you can find the solution here: http://accesschecker.codeplex.com/
Hey there, I work on SharePoint
If you have MOSS installed you might take a look at the 'audiences' functionality, that allows you to target different folks without code.
Hello agnieszka,
I stumbled upon your post because I have (IMHO) the exact same question, but the replies seem somehow not to match that. So I went on searching and found http://www.eggheadcafe.com/conversation.aspx?messageid=30460140&threadid=30420861:
SPWeb site = SPContext.Current.Web;
SPGroup managerGroup = site.Groups["SP_Project_Manager"];
bool isManager = site.IsCurrentUserMemberOfGroup(managerGroup);