del método SPList.GetUserEffectivePermissions
Obtiene los permisos efectivos que disponga de un usuario especificado en la lista.
Espacio de nombres: Microsoft.SharePoint
Ensamblado: Microsoft.SharePoint (en Microsoft.SharePoint.dll)
Sintaxis
'Declaración
Public Overrides Function GetUserEffectivePermissions ( _
userName As String _
) As SPBasePermissions
'Uso
Dim instance As SPList
Dim userName As String
Dim returnValue As SPBasePermissions
returnValue = instance.GetUserEffectivePermissions(userName)
public override SPBasePermissions GetUserEffectivePermissions(
string userName
)
Parámetros
userName
Tipo: System.StringEl nombre del usuario cuyos permisos se se va a devolver.
Valor devuelto
Tipo: Microsoft.SharePoint.SPBasePermissions
Una combinación bit a bit de valores de enumeración que especifica un conjunto de permisos.
Excepciones
Excepción | Condición |
---|---|
UnauthorizedAccessException | El usuario actual no tiene el permiso para enumerar los permisos. |
Ejemplos
En el siguiente ejemplo es una aplicación de consola que enumera todos los usuarios de todos los grupos de un sitio Web, comprobar si cada usuario tiene el permiso ApproveItems en la biblioteca de documentos compartidos. Para obtener un ejemplo que muestra otro enfoque para la misma tarea, vea el método DoesUserHavePermissions(SPUser, SPBasePermissions) .
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();
}
}
}