Skip to main content
added 151 characters in body
Source Link
pomo
  • 35
  • 3

I am checking permissions if a user has permissions (at least read) to a calendar page on sharepoint online. This code does not seem to always work meaning give Access Denied even though I can see the calendar by going to the URL. Code always breaks at last Executequery so I know it sees the list. Also, not sure if it checks if Everyone as access to and therefor the user does. CalendarUrl: https://microsoft.sharepoint.com/stuff/stuffer/Lists/theCal/calendar.aspx siteUrl = "https://microsoft.sharepoint.com/stuff/stuffer"

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
}

What should I do to get an 'OK' for a user to have permission on the calendar page either directly or through "Everyone" setting on the calendar page? Thanks again.

I am checking permissions if a user has permissions (at least read) to a calendar page on sharepoint online. This code does not seem to always work. Also, not sure if it checks if Everyone as access to and therefor the user does. CalendarUrl: https://microsoft.sharepoint.com/stuff/stuffer/Lists/theCal/calendar.aspx siteUrl = "https://microsoft.sharepoint.com/stuff/stuffer"

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
}

What should I do to get an 'OK' for a user to have permission on the calendar page either directly or through "Everyone" setting on the calendar page? Thanks again.

I am checking permissions if a user has permissions (at least read) to a calendar page on sharepoint online. This code does not seem to always work meaning give Access Denied even though I can see the calendar by going to the URL. Code always breaks at last Executequery so I know it sees the list. Also, not sure if it checks if Everyone as access to and therefor the user does. CalendarUrl: https://microsoft.sharepoint.com/stuff/stuffer/Lists/theCal/calendar.aspx siteUrl = "https://microsoft.sharepoint.com/stuff/stuffer"

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
}

What should I do to get an 'OK' for a user to have permission on the calendar page either directly or through "Everyone" setting on the calendar page? Thanks again.

Source Link
pomo
  • 35
  • 3

Proper Way to check page permissions for Sharepoint Online

I am checking permissions if a user has permissions (at least read) to a calendar page on sharepoint online. This code does not seem to always work. Also, not sure if it checks if Everyone as access to and therefor the user does. CalendarUrl: https://microsoft.sharepoint.com/stuff/stuffer/Lists/theCal/calendar.aspx siteUrl = "https://microsoft.sharepoint.com/stuff/stuffer"

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
}

What should I do to get an 'OK' for a user to have permission on the calendar page either directly or through "Everyone" setting on the calendar page? Thanks again.