Freigeben über


SPList.DoesUserHavePermissions-Methode (SPUser, SPBasePermissions)

Gibt an, ob der angegebene Benutzer in der Liste den angegebenen Satz von Berechtigungen verfügt.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Function DoesUserHavePermissions ( _
    user As SPUser, _
    permissionMask As SPBasePermissions _
) As Boolean
'Usage
Dim instance As SPList
Dim user As SPUser
Dim permissionMask As SPBasePermissions
Dim returnValue As Boolean

returnValue = instance.DoesUserHavePermissions(user, _
    permissionMask)
public bool DoesUserHavePermissions(
    SPUser user,
    SPBasePermissions permissionMask
)

Parameter

Rückgabewert

Typ: System.Boolean
true , wenn der Benutzer die Berechtigungen besitzt; andernfalls false.

Ausnahmen

Ausnahme Bedingung
UnauthorizedAccessException

Der aktuelle Benutzer hat keinen EnumeratePermissions rechts.

Beispiele

Im folgende Beispiel ist eine Konsolenanwendung, die alle Benutzer in allen Gruppen einer Website überprüfen, ob jeder Benutzer einen bestimmten Satz von Berechtigungen in der Liste Freigegebene Dokumente auflistet.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")
         Using web As SPWeb = site.RootWeb

            Dim perms As SPBasePermissions = SPBasePermissions.AddListItems _
                                          Or SPBasePermissions.ApproveItems _
                                          Or SPBasePermissions.CancelCheckout _
                                          Or SPBasePermissions.DeleteListItems _
                                          Or SPBasePermissions.DeleteVersions _
                                          Or SPBasePermissions.EditListItems _
                                          Or SPBasePermissions.Open _
                                          Or SPBasePermissions.OpenItems _
                                          Or SPBasePermissions.ViewListItems _
                                          Or SPBasePermissions.ViewVersions

            Dim listUrl As String = web.RootFolder.ServerRelativeUrl + "shared documents"
            Dim list As SPList = web.GetList(listUrl)

            ' Be sure the current user has permission to check permissions.
            If web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions) Then

               For Each group As SPGroup In web.Groups
                  For Each user As SPUser In group.Users
                     ' Check another user's permissions.
                     Dim hasPermission As Boolean = list.DoesUserHavePermissions(user, perms)
                     Console.WriteLine("{0, -5}  {1}", hasPermission, user.LoginName)
                  Next
               Next

            End If

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub
End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://localhost"))
         {
            using (SPWeb web = site.RootWeb)
            {
               SPBasePermissions perms = SPBasePermissions.AddListItems
                                       | SPBasePermissions.ApproveItems
                                       | SPBasePermissions.CancelCheckout
                                       | SPBasePermissions.DeleteListItems
                                       | SPBasePermissions.DeleteVersions
                                       | SPBasePermissions.EditListItems
                                       | SPBasePermissions.Open
                                       | SPBasePermissions.OpenItems
                                       | SPBasePermissions.ViewListItems
                                       | SPBasePermissions.ViewVersions;


               string listUrl = web.RootFolder.ServerRelativeUrl + "shared documents";
               SPList list = web.GetList(listUrl);

               // Be sure the current user has permission to check permissions.
               if (web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions))
               {
                  foreach (SPGroup group in web.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);
                     }
                  }
               }
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

Siehe auch

Referenz

SPList Klasse

SPList-Member

DoesUserHavePermissions-Überladung

Microsoft.SharePoint-Namespace