SPList.GetUserEffectivePermissions 方法
获取指定的用户具有列表的有效权限。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Overrides Function GetUserEffectivePermissions ( _
userName As String _
) As SPBasePermissions
用法
Dim instance As SPList
Dim userName As String
Dim returnValue As SPBasePermissions
returnValue = instance.GetUserEffectivePermissions(userName)
public override SPBasePermissions GetUserEffectivePermissions(
string userName
)
参数
userName
类型:System.String要返回其权限的用户名称。
返回值
类型:Microsoft.SharePoint.SPBasePermissions
指定一组权限枚举值的按位组合。
异常
异常 | 条件 |
---|---|
UnauthorizedAccessException | 当前用户没有枚举权限的权限。 |
示例
下面的示例是枚举所有的检查每个用户是否具有共享文档库上的ApproveItems权限的用户的网站的所有组中的一个控制台应用程序。显示另一种方法相同的任务的示例,请参阅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();
}
}
}