Revision #1

You are currently reviewing an older revision of this page.
Go to current version
This article will show you how to manage user permissions inside of SharePoint 2010. This enables you to change the read and write permissions for individuals and groups of users across your organization.

NOTE: This is a stub article. Please add more information when it becomes available.
 
Example 1. How to set permissions to SPListItem.

public void SetSPListItemUserPermissions(SPListItem listItem, SPUser user, SPRoleType roleType)

{

    //Break role inheritance

    if (!listItem.HasUniqueRoleAssignments)

        listItem.BreakRoleInheritance(false);

    //Create new role

    var roleDefinition = listItem.Web.RoleDefinitions.GetByType(roleType);

    var roleAssignment = new SPRoleAssignment(user);

    roleAssignment.RoleDefinitionBindings.Add(roleDefinition);

        

    //Assign new role

    listItem.RoleAssignments.Add(roleAssignment);

    listItem.Update();

}

Example 2. How to restore permissions to SPListItem

public void RestoreSPListItemUserPermissions(SPListItem listItem)

{

    if (listItem.HasUniqueRoleAssignments)

        listItem.ResetRoleInheritance();

}

 

 

Revert to this revision