Item Level Permissions and Code Access

Item Level Permissions and Code Access

In this article we can explore how Item Level Permissions behave in Code Access scenario.

Item Level Permissions

We can enable Item-level Permission on a list so that only the Creator will be able to Read the item.  For other users the item won’t be displayed.

As an Administrator, you can go to the List > List Settings > Advanced Settings to enable Item-level Permissions.

i1

Testing from Browser Access

Create a new item as Administrator User.

i2

Now login as a different User who is just a Contributor.  You won’t’ be able to see the Admin item now.

i3

Now create a new item.

i4

Now login back as the Administrator or Site Owner & You can see both the items.

image.png

Site Collection Administrator or Site Owner can view all the Use Items.

Testing from Code Access

Now let us see the Item-level Permission applies to Code Access as well.  For this I am using CSOM Code with/without Network Credential class.

By default the code runs under Login User which is Administrator.

static void Main(string[] args)

{

ClientContext context = new ClientContext(“http://sharepoint“);

List list = context.Web.Lists.GetByTitle(“Restricted Contacts”);

ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());

context.Load(items);

context.ExecuteQuery();

foreach (var item in items)

{

Console.WriteLine(item[“Title”]);

}

 

Console.ReadKey(false);

}

Executing the Code you can see both the items are displayed.  Since we are Administrator user now.

i5

Now apply the Contributor User Credential to test the User Context.

ClientContext context = new ClientContext(“http://sharepoint“);

context.Credentials = new NetworkCredential(“tim”, “Welcome123”);

i6

This concludes that Item-level Permission applies to Code Access as well & Site Collection Administrators or Site Owner can view all items in both browser & code access scenario.

image.png

Item-level Permissions is a great feature.  Without this we would have required custom code to break the permission & assign permission to the created user.

References

http://bit.ly/1PYkb8o

Summary

In this article we have explored Item Level Permissions & CSOM Code with different User Contexts.

 

Leave a Reply

Your email address will not be published. Required fields are marked *