Item Level Permission

Item Level Permission For Documentry Library.

using

(SPSite WebApp = SPContext.Current.Site)
{
using (SPWeb objWeb = objSite.OpenWeb()){
try
{ 

SPList list = Site.Lists[“MKSLib”];
SPListItem  item = list.Items[0]; 

 

SPRoleDefinition RoleDefinition =
Site.RoleDefinitions.GetByType(
SPRoleType.Contributor); 

 

SPRoleAssignment RoleAssignment =
new SPRoleAssignment(“<domain>\\<user>”, “email”, “name”, “notes”);
RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);

 

 

if

(!item.HasUniqueRoleAssignments){
item.BreakRoleInheritance(

true);
}item.RoleAssignments.Add(RoleAssignment);

item.Update();

}

 

 

catch (Exception ex){

 

SPList list = Site.Lists[“MKSLib”];
SPListItem  item = list.Items[0]; 

 

SPRoleDefinition RoleDefinition =
Site.RoleDefinitions.GetByType(
SPRoleType.Contributor); 

 

SPRoleAssignment RoleAssignment =
new SPRoleAssignment(“<domain>\\<user>”, “email”, “name”, “notes”);
RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);

 

 

if

(!item.HasUniqueRoleAssignments){
item.BreakRoleInheritance(

true);
}item.RoleAssignments.Add(RoleAssignment);

item.Update();

}

 

 

catch (Exception ex){

  }

 

Assigning Role To a Group

//Assign Role Permission to Group//

 

SPRoleAssignment groupRoleAssigment = new SPRoleAssignment(objSPWeb.SiteGroups[groupName]); 

//Defining Role Permission

 

SPRoleDefinition groupRoleDefinition = objSPWeb.RoleDefinitions[“Read”]; 

//Binding Permission to Role Goroup

groupRoleAssigment.RoleDefinitionBindings.Add(groupRoleDefinition);

 

//Associating Group to List/Item

objSPWeb.Site.RootWeb.RoleAssignments.Add(groupRoleAssigment);

 

// objSPWeb.Lists[DOCUMENTNAME].RoleAssignments.Add(groupRoleAssigment);

 

//web update

 

Assign Item Level Permission To Task in WorkFlow

#region

PERMISSION 

CreateTask objCreateTask = sender as CreateTask; 

HybridDictionary permsCollection = new HybridDictionary();permsCollection.Add(SerialApprovalTaskProperty.AssignedTo,

SPRoleType.Contributor);objCreateTask.SpecialPermissions = permsCollection;

#endregion

 

Advertisements

One thought on “Item Level Permission

  1. Pingback: Setting Item Level Permissions Programmatically | Rehman Gul Professional Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s