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 bool DoesUserHavePermissions(
	string login,
	SPBasePermissions permissionMask


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.

using System;
using Microsoft.SharePoint;

namespace Test
    class Program
        static void Main(string[] args)
            using (SPSite site = new SPSite("http://localhost"))
                using (SPWeb web = site.OpenWeb())
                    // Make sure the current user can enumerate permissions.
                    if (web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions))
                        // Specify the permission to check.
                        SPBasePermissions permissionToCheck = SPBasePermissions.ManageLists;
                        Console.WriteLine("The following users have {0} permission:", permissionToCheck);

                        // Check the permissions of users who are explicitly assigned permissions.
                        SPUserCollection users = web.Users;
                        foreach (SPUser user in users)
                            string login = user.LoginName;
                            if (web.DoesUserHavePermissions(login, permissionToCheck))