C# Check SharePoint List permissions using SharePoint Client Object Model

4k views Asked by At

From a client application, I need to check if a given user has permissions on a given document library using Client object Model. I want something equivalent of the following Server object function

spList.DoesUserHavePermissions(SPBasePermissions.EditListItems);
spList.DoesUserHavePermissions(SPBasePermissions.ManageLists);
spList.DoesUserHavePermissions(SPBasePermissions.AddListItems);
spList.DoesUserHavePermissions(SPBasePermissions.AddListItems)

Thank you !

2

There are 2 answers

0
Maha Rizk On BEST ANSWER

I found a solution mentioned in this Blog for listItems permissions, and it worked fine for list. the solution is as follow:

private static bool DoesUserHasPermission(ClientContext context, List list, PermissionKind permissionKind)
        {
            context.Load(list, t => t.EffectiveBasePermissions);
            context.ExecuteQuery();

            return list.EffectiveBasePermissions.Has(permissionKind);
        }

0
Icaro Camelo On

From a client application the best approach would be use SharePoint web service. Sharepoint contains a lot of services that are usable for remote development by third-party developers.

In your case, I recommend use SharePoint Permission web service (http:///_vti_bin/permissions.asmx).

You could query Sharepoint about items permissions. Here is a step-by-step tutorial : http://jamestsai.net/Blog/post/Understand-SharePoint-Permissions-Part-2-Check-SharePoint-usergroup-permissions-with-Permissions-web-service-and-JavaScript.aspx