SPList.DoesUserHavePermissions 方法 (SPUser, SPBasePermissions)
指示指定的用户是否在列表上具有指定的权限集。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Function DoesUserHavePermissions ( _
user As SPUser, _
permissionMask As SPBasePermissions _
) As Boolean
用法
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
)
参数
user
类型:Microsoft.SharePoint.SPUser验证权限为用户。
permissionMask
类型:Microsoft.SharePoint.SPBasePermissions指定一组权限枚举值的按位组合。
返回值
类型:System.Boolean
true如果用户具有的权限 ;否则为false。
异常
异常 | 条件 |
---|---|
UnauthorizedAccessException | 当前用户没有EnumeratePermissions右侧。 |
示例
下面的示例是枚举所有的检查每个用户是否具有共享文档列表上的一组特定的权限的用户的网站的所有组中的一个控制台应用程序。
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();
}
}
}