Is it possible to determine if a user can access a given item identified by its url without the users context - it has to be done with CSOM.
Code so far:
var file = web.GetFileByServerRelativeUrl(relative);
clientContext.Load(file, f => f.ListItemAllFields);
clientContext.ExecuteQuery();
var listitem = file.ListItemAllFields;
clientContext.Load(listitem, f => f.RoleAssignments.Include(r => r.RoleDefinitionBindings, r => r.Member), f => f.RoleAssignments.GetByPrincipal(user)); // <= this line breaks it
clientContext.ExecuteQuery();
RoleAssignmentCollection roleAssignments = listitem.RoleAssignments;
Or with another call:
bool hasPermissions = false;
var roleAssignment = roleAssignments.GetByPrincipal(user); // <= breaks
clientContext.ExecuteQuery();
foreach (RoleDefinition role in roleAssignment.RoleDefinitionBindings)
{
hasPermissions = role.BasePermissions.Has(PermissionKind.Open);
if (hasPermissions) break;
}
I tried many combinations but every time I use GetByPrincipal I get an exception. Any pointers?
clientContext.Credentials = new NetworkCredential("user", "password", "domain");