Question

I am trying to check permissions for SharePoint users in c# and I came across the following code that seems to work:

isGranted = spweb.DoesUserHavePermissions(userlogin, SPBasePermissions.EmptyMask | SPBasePermissions.ViewPages);

The first argument is the user to check a permission of. The second argument is the permission to check if the user has.

My question is, what is the result of the bitwise-or between emptymask and viewpages permissions? What permission is this actually checking against?

Was it helpful?

Solution

Since EmptyMask is defined as zero, the result is the same as passing the SPBasePermissions.ViewPages with no EmptyMask:

[Flags]
public enum SPBasePermissions
{
    EmptyMask =                 0×0000000000000000,
    ...
}

OTHER TIPS

It's checking against both permissions. The permissions are bitwise flags.

I don't know the actual values, but say Empty Mask is: 01000000, and ViewPage is 00100000 - then OR'ing them would be 01100000 - so you get both of them together.

So then if you want to check that a user has the ViewPage permission, you can take the OR'ed value, AND it against the value for ViewPage, and if it's > 0 then you know you have permission.

The enumeration has the Flag attribute, which indicates you can combine values using bitwise operators.

Actually, this makes no sense to combine EmptyMask (which is 0) with another value, as 0 | X is always equal to X. Just use the other value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top