COLLAB365

Auto-Tagging Add-In

Webcasts

My Apps on the SharePoint Store

Recent blog posts

User login

Home | Blogs | Stephane Eyskens's blog

Checking the current user permissions on a list object via the Client Object Model

Hi,

In regular server-side SharePoint coding, when we want to check whether the current user has specific permissions on a list, we can use the method SPList.DoesUserHavePermissions(). This method isn't available from the Client Object Model but you can easily create your own this way:

You can use a similar technique with the Silverlight Client OM but you'll be forced to check asynchroneously!

Happy coding!

class Program
{
static ClientContext Ctx = null;

static void Main(string[] args)
{
Ctx = new ClientContext("http://intranet/sites/clients");
if (DoesUserHavePermissions("Clients", PermissionKind.AddListItems))
{
//User is a list contributor
}

}

static bool DoesUserHavePermissions(string listname, PermissionKind permmask)
{
List TargetList = Ctx.Web.Lists.GetByTitle(listname);
Ctx.Load(TargetList,T=>T.EffectiveBasePermissions);
Ctx.ExecuteQuery();
return TargetList.EffectiveBasePermissions.Has(permmask);
}

}