SPWeb.DoesUserHavePermissions method (String, SPBasePermissions)

Indicates whether the specified user has a specified set of permissions.

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

Public Function DoesUserHavePermissions ( _
	login As String, _
	permissionMask As SPBasePermissions _
) As Boolean
Dim instance As SPWeb
Dim login As String
Dim permissionMask As SPBasePermissions
Dim returnValue As Boolean

returnValue = instance.DoesUserHavePermissions(login, _


Type: System.String

The user name (Domain\User_Alias).

Type: Microsoft.SharePoint.SPBasePermissions

A bitwise combination of enumeration values that specifies a set of permissions.

Return value

Type: System.Boolean
true if the user has the specified permissions; otherwise, false.

This method tests whether the permissions in permissionMask match those returned by GetUserEffectivePermissions(String).

The current user must have EnumeratePermissions rights to check the permissions of other users.

The following example is a console application that prints a list of users who have been explicitly assigned permission to manage the list on the current website.

Imports System
Imports Microsoft.SharePoint

Module Test

    Sub Main()
        Using site As SPSite = New SPSite("http://localhost")
            Using web As SPWeb = site.OpenWeb()

                ' Make sure the current user can enumerate permissions.
                If web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions) Then
                    ' Specify the permission to check.
                    Dim permissionToCheck As SPBasePermissions = SPBasePermissions.ManageLists
                    Console.WriteLine("The following users have {0} permission:", permissionToCheck)

                    ' Check the permissions of users who are explicitly assigned permissions.
                    Dim users As SPUserCollection = web.Users
                    Dim user As SPUser
                    For Each user In users
                        Dim login As String = user.LoginName
                        If web.DoesUserHavePermissions(login, permissionToCheck) Then
                        End If
                End If

            End Using
        End Using
    End Sub

End Module