Software Technology Tips

SharePoint site security helps manage permissions for different resources within a site by defining the levels of accessibility permissions for different peoples and groups. In SharePoint, always the top-level or the parent level permissions are inherited to it's child contents (e.g. a sub-site inheriting permissions from it's parent site collection).
 
In-order to create unique permission we need to break the inheriting parent permission and create new permission level for the SharePoint content. These permissions can be defined for specific users or groups.
 
Provided below is an example using C# for defining custom permission for a list item.

// assign a item to SPListItem object.
SPListItem objLstitem = objLst.Items[0]; // objLst is the SPList object

// get the user by ID/Email
// objSpWeb is the SpWeb object

SPUser objUser = objSpWeb.SiteUsers.GetByEmail("
user@mydomain.com");

// Break inheriting parent permissions for this List Item.
objLstitem.BreakRoleInheritance(false);

// assign Role to the defined User
SPRoleDefinitionCollection objWebRoleDefn = objSpWeb.RoleDefinitions;
SPRoleAssignment objRoleAssign = new SPRoleAssignment(objUser);

// specify the name of the role definition like [Full Control][Read][Contribute] etc.
objRoleAssign.RoleDefinitionBindings.
Add(objWebRoleDefn["Contribute"]);
objLstitem.RoleAssignments.Add(objRoleAssign);


Related Tags:

SharePoint

Author: Samarendra Swain

SharePoint

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

This site uses cookies. We respect your privacy.copyright (c) Mindfire Solutions 2007-2015. Login