Find what SharePoint groups a user belongs to.

From: Brian Hman (bhbhbh_at_community.nospam)
Date: 04/20/05

  • Next message: Rich S.: "How to Create a File"
    Date: Wed, 20 Apr 2005 14:11:03 -0700
    
    

    Within a web part, I need to hide a particular control from certain users. We
    have set up groups within sharepoint to determine if a user should see this
    control.

    I was using the following code to do that:

    SPSite site = SPControl.GetContextSite(Context);
    SPWeb web = site.OpenWeb();
    SPUser user = web.CurrentUser;
    //we did not make cross site groups. we do not have multiple sites.
    SPRoleCollection groupRole = user.Roles;
    Hashtable rolesForUser = new Hashtable();

    foreach(SPRole role in groupRole)
    {
       rolesForUser.Add(role.Name, user.Name);
    }

    This works but only if the user is part of the Admin group along with their
    other group memberships. How can I do the same thing and not make everyone
    admin? I prefer not to use impersonation.

    Thanks for your help
    Brian Hman


  • Next message: Rich S.: "How to Create a File"

    Relevant Pages

    • Re: SP1 setup fails. Access is denied
      ... not sure where to find admin group in the root branch, ... > control in the hkey_classes_root branch of the registry. ... >> Windows Server 2003 has been partially updated and may not work properly. ...
      (microsoft.public.windows.server.setup)
    • Scheduled Task will not run on Win2K3 Server (Ent Edition)
      ... control on the folders where the application is stored. ... The local admin group also has full control on the ... Registry key that the application created to store ...
      (microsoft.public.windows.server.general)
    • RE: System policy control
      ... fully manage their admin group ... I understand that you want to limit other Exchange admins to ... In Exchange 2003 we can delegate administrators ... and then click "Delegate control". ...
      (microsoft.public.exchange.admin)
    • Permissions denied on shared folder
      ... My site is attemting to write to a shared folder but get's access denied. ... The ASPNET account is part of the admin group and has full control on the share. ...
      (microsoft.public.dotnet.general)
    • Re: Active Directory Madness
      ... > for a very simple workgroup configuration but, after some network ... > be in the admin group of their own machine and that would do the job, ... machine and go to Control Panel -> User Accounts. ... with the user name "JSmith" and put your Domain name in the Domain ...
      (microsoft.public.windows.server.general)