tags:

views:

1150

answers:

5

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.

+3  A: 

Hi 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

Henrik P. Hessel
A: 

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/

Kasper
A: 

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.

Kevin Davis
A: 

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&amp;threadid=30420861:

SPWeb site = SPContext.Current.Web;
SPGroup managerGroup = site.Groups["SP_Project_Manager"];
bool isManager = site.IsCurrentUserMemberOfGroup(managerGroup);
chiccodoro
A: 

Can we get the same in Sharepoint designer?

Georgil Mathew