2

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?

dave823
  • 1,191
  • 2
  • 15
  • 32
  • 2
    See this question for details of enum bitwise operations: http://stackoverflow.com/questions/1285986/flags-enum-bitwise-operations-vs-string-of-bits – dmck Mar 18 '13 at 13:23
  • 2
    The easiest way would be to cast the values to their underlying type and find out yourself. *Guessing* by the name, `EmptyMask` is probably `0` and doesn't really do anything here, but I might be completely wrong... – lc. Mar 18 '13 at 13:24

3 Answers3

6

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,
    ...
}
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
1

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.

PhonicUK
  • 13,486
  • 4
  • 43
  • 62
1

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.

ken2k
  • 48,145
  • 10
  • 116
  • 176