0

I am trying to create a web part that will list the site owners of a SharePoint site. I'm not sure where to start. I've been unable to figure out how to access the permissions property of a site.

Any help would be much appreciated!

2 Answers 2

1

You can try the following code snippet:

using (SPSite site = new SPSite(args[0]))

                    foreach(SPWeb web in site.AllWebs)
                    {
                        //SPUserCollection allAdmins = web.AssociatedOwnerGroup;
                        SPGroup ownerGroup = web.AssociatedOwnerGroup;
                        if (ownerGroup != null)
                        {

                            foreach (SPUser user in ownerGroup.Users)
                            {
                                Console.WriteLine(web.Url +"\t"+ ownerGroup.Name + "\t" + user.Name);
                            }
                        }
                        web.Dispose();
                    }
2
  • Thanks! I edited the code a little to work with what I had and it works.
    – Mischa
    Jun 24, 2014 at 14:49
  • you can mark this as answer if it solves your issue.
    – Aanchal
    Jun 24, 2014 at 15:05
0

To access permissions, you should just be able to click Site Actions> Site Permissions. If you dont see this then you dont have proper permissions to do so. If you can, then it will open to reveal the permissions for the site.

To display your site owners on the site: Edit the page and add the 'Site Users' WebPart. From the small arrow drop-down, click 'Edit Web Part'. Under 'Site Users' click the 'Show People in this Group' radio button and enter the name of the site owner group. Click ok and the webpart will display the people in that group.

1
  • Thanks. I know about the Site Users Web Part, but I'm trying to create my own.
    – Mischa
    Jun 24, 2014 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.