Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a document library which does not inherit the site's permissions ('Custom permissions' is set).

How do I find out who has administrator permissions to this library, using C#?

share|improve this question
add comment

1 Answer 1

I believe the function you're looking for is SPList.DoesUserHavePermissions

Here is a slightly modified version of the example on that page, which may do what you need:

using (SPSite site = new SPSite("http://your/site/here"))
{
   SPBasePermissions perms = SPBasePermissions.ManageLists;

   string listUrl = site.RootWeb.RootFolder.ServerRelativeUrl + "Your Document Library Name";
   SPList list = site.RootWeb.GetList(listUrl);

   // Be sure the current user has permission to check permissions.
   if (site.RootWeb.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions))
   {
      foreach (SPGroup group in site.RootWeb.Groups)
      {
         foreach (SPUser user in group.Users)
         {
            // Check another user's permissions.
            bool hasPermission = list.DoesUserHavePermissions(user, perms);
            Console.WriteLine("{0, -5}  {1}", hasPermission, user.LoginName);
         }
      }
    }
}
share|improve this answer
1  
Side note: Never put a using around a site's RootWeb, it will cause exceptions. Pretty much the rule of thumb is: if you "own" (i.e. created) the disposable object, then dispose it. If it is created by the SharePoint API, don't –  Colin Mar 18 '12 at 3:07
    
@Colin: Good call. I should've spotted that error in the example. I've updated the code accordingly. –  Stuart Pegg Mar 19 '12 at 13:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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