2

There is a simple function to add permissions to collection:

// Set up permissions.
BasePermissions permissions = new BasePermissions();
permissions.Set(PermissionKind.ViewListItems);
permissions.Set(PermissionKind.AddListItems);
permissions.Set(PermissionKind.EditListItems);
permissions.Set(PermissionKind.DeleteListItems);

But how to get assigned permissions back from existing BasePermissions object? I cannot find a function for that. There is only a function to check, if specific kind of permission is assigned or not. How to get the list of all assigned PermissionKind's?

Thank you.

2

After searching for a solution, I found nothing better than just sequentially checking all possible permissions to find right one as follows:

  PermissionKind kind = PermissionKind.EmptyMask;
  foreach (PermissionKind k in Enum.GetValues(typeof(PermissionKind)))
  {
    if (roleDefinition.BasePermissions.Has(k)) 
      kind = k;
    else break;
  }

Because integer values for enumeration consistently increase, this must stop cycle on maximum available permission. Hope somebody could find a better way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.