SPList.GetUserEffectivePermissions-Methode
Ruft die effektiven Berechtigungen, die ein bestimmten Benutzer in der Liste hat.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaration
Public Overrides Function GetUserEffectivePermissions ( _
userName As String _
) As SPBasePermissions
'Usage
Dim instance As SPList
Dim userName As String
Dim returnValue As SPBasePermissions
returnValue = instance.GetUserEffectivePermissions(userName)
public override SPBasePermissions GetUserEffectivePermissions(
string userName
)
Parameter
userName
Typ: System.StringDie Namen der Benutzer, dessen Berechtigungen zurückgegeben werden sollen.
Rückgabewert
Typ: Microsoft.SharePoint.SPBasePermissions
Eine bitweise Kombination der Enumerationswerte, die einen Satz von Berechtigungen angibt.
Ausnahmen
Ausnahme | Bedingung |
---|---|
UnauthorizedAccessException | Der aktuelle Benutzer besitzt nicht die Berechtigung zum Auflisten der Berechtigungen. |
Beispiele
Im folgende Beispiel ist eine Konsolenanwendung, die alle Benutzer in allen Gruppen einer Website überprüfen, ob jeder Benutzer die Berechtigung ApproveItems auf die Bibliothek Freigegebene Dokumente auflistet. Finden Sie ein Beispiel für einen anderen Ansatz für die gleiche Aufgabe die DoesUserHavePermissions(SPUser, SPBasePermissions) -Methode.
Imports System
Imports Microsoft.SharePoint
Module Test
Sub Main()
Using site As SPSite = New SPSite("https://localhost")
Using web As SPWeb = site.OpenWeb()
' Get a list to check permissions on.
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
' Get the rights mask for a user.
Dim permMask As SPBasePermissions = list.GetUserEffectivePermissions(user.LoginName)
' Check if the user has a specific right.
Dim hasPermission As Boolean = (permMask & SPBasePermissions.ApproveItems) <> 0
Console.WriteLine("{0} {1} permission to approve items.", _
user.LoginName, IIf(hasPermission, "has", "does not have"))
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 Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
// Get a list to check permissions on.
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)
{
// Get the rights mask for a user.
SPBasePermissions permMask = list.GetUserEffectivePermissions(user.LoginName);
// Check if the user has a specific right.
bool hasPermission = (permMask & SPBasePermissions.ApproveItems) != 0;
Console.WriteLine("{0} {1} permission to approve items.",
user.LoginName, hasPermission ? "has" : "does not have");
}
}
}
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}