|
Ever needed to control a set of users and level of access they have to SharePoint document libraries, lists, sites etc? In SharePoint 2010 there are few new methods that simplify the life from a developers stand point to leverage custom permissions levels. Here I`ll show you how to create custom permission levels programmatically, so you can call them from the feature receiver when creating a site from your site template: 1. First we create custom permission level with the name and description and set of permissions you can find here SPRoleDefinition role = new SPRoleDefinition();
role.BasePermissions = SPBasePermissions.OpenItems | SPBasePermissions.EditListItems | SPBasePermissions.ViewListItems | SPBasePermissions.ViewPages | SPBasePermissions.Open | SPBasePermissions.ViewFormPages;
role.Name = “My Role Name”;
role.Description = “My Role Description”;
rootWeb.RoleDefinitions.Add(role);
2. Then we assign a set of permissions to an existing group in this case called MyGroup SPRoleAssignment roleAssignment = new SPRoleAssignment(rootWeb.SiteGroups["MyGroup"]); roleAssignment.RoleDefinitionBindings.Add(role); rootWeb.RoleAssignments.Add(roleAssignment); If you’re reading this you probably spent about 10 minutes trying to find this particular code. Here is something I found very usefull if you’re developing for MOSS or SharePoint 2010: a great set of SharePoint snippents from CodePlex Enjoy! http://www.sharemuch.com/2010/03/02/creating-sharepoint-2010-permissions-levels/ |
Creating SharePoint 2010 permission levels

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare