1

I have read access to a sharepoint calendar and can view the page with no issues. I do not have access to the site though which is by design. I am using the code below to check if I have permission to the site. Some calendars work while others don't even though I can see events on the various calendars.

using (ClientContext clientContext = new ClientContext(url)
{
  clientContext.Credentials = onlineCredentials;
  string userLoginName = "i:0#.f|membership|" + owner.ToLower();
  List oList = clientContext.Web.Lists.GetByTitle(listName);
  clientContext.Load(oList);
  var effectPermissions = oList.GetUserEffectivePermissions(userLoginName);
  clientContext.ExecuteQuery();
  if (effectPermissions.Value.Has(PermissionKind.ViewListItems))
  {
      return CallStatus.OK;
  }
}

Is the GetUserEffectivePermissions check only a certain level of permission? Cant figure out why some calendars get the OK while others don't. Thanks.

0
try
{
    ClientContext clientContext = new ClientContext(siteUrl);
    string userLogin = "i:0#.f|membership|" + owner.ToLower();
    List oList = clientContext.Web.Lists.GetByTitle(listName);
    clientContext.Load(oList);
    clientContext.ExecuteQuery();

    User usr = clientContext.Web.EnsureUser(userLogin);
    clientContext.Load(usr);
    clientContext.ExecuteQuery();

    ClientResult<BasePermissions> result = item.GetUserEffectivePermissions(usr.LoginName);
    clientContext.ExecuteQuery();

    if(result.Value.Has(PermissionKind.ViewListItems))
    {
        return CallStatus.Ok;
    }
}
catch (Exception ex)
{
    //User has no permission
}

OK will get returned if the user has ViewListItems permission.

Check the PermissionKind enumeration

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.permissionkind(v=office.15).aspx

3
  • As my code above illustrates, I am using: effectPermissions.Value.Has(PermissionKind.ViewListItems) But I am using getting the catch (WebException ex) { return CallStatus.UnAuthorized; } – pomo Oct 29 '14 at 17:58
  • @pomo i have updated my answer – Amal Hashim Oct 29 '14 at 18:18
  • Thank you. I used the code you provided and I get the same results. Some calendars I can get an OK while others I get an Access Denied. So my issue must be my logic. What level permissions does a user need to get an OK? I am able to view the calendar pages no problem. If I have a url: microsoft.sharepoint.com/teams/stuff/stuffer/Lists/Calendar/… Would my siteurl be microsoft.sharepoint.com/teams/stuff/stuffer – pomo Oct 31 '14 at 5:42

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.