Posted By:Jayasankar kesarla
Posted Date: February 28, 2011
Points: 200
Category: SharePoint
URL: http://www.sunilyadav.net
This article explains how we can create Creating a Custom Permission Level in Sharepoint 2010.
This article explains how we can create Creating a Custom Permission Level in Sharepoint 2010.
In one of my project there was a requirement to create a Custom permission when creating a new site from site definition.
Here is the solution to above.
Here i am creating custom permission and groups using Client object model.
Newly created site permissions.

http://msdn.microsoft.com/en-us/library/bb861862(office.12).aspx
http://msdn.microsoft.com/en-us/library/ff382738(office.12).aspx
Happy
SharePointing!!!!!!!
1. Create a new Sharepoint 2010 project and select blank sharepoint 2010 project.
2. Specify a site to deploy the solution.
3.Right click on the project and add reference to Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime.
4. Right click on the feature section and new Feature.
5. Right click on newly created feature and add event receiver.
6. Add below code in the event reciever class and deploy the project.
01 | private void CreatePermission() |
02 | { |
03 | using (OM.ClientContext context = new OM.ClientContext(SPContext.Current.Site.Url)) |
04 | { |
05 | OM.BasePermissions permissions = new OM.BasePermissions(); |
06 | OM.PermissionKind
permissonkind = OM.PermissionKind.AddListItems |
OM.PermissionKind.ApproveItems | OM.PermissionKind.BrowseUserInfo |
OM.PermissionKind.ManageLists | OM.PermissionKind.ManagePermissions | |
07 | OM.PermissionKind.Open
| OM.PermissionKind.ViewFormPages | OM.PermissionKind.ViewPages |
OM.PermissionKind.ViewVersions | OM.PermissionKind.EnumeratePermissions |
OM.PermissionKind.EditListItems | OM.PermissionKind.DeleteListItems; |
08 | permissions.Set(permissonkind); |
09 |
10 | OM.RoleDefinitionCreationInformation roledefinition = new OM.RoleDefinitionCreationInformation(); |
11 | roledefinition.Name = "Administrator" ; |
12 | roledefinition.Description = "This is site administrator Permission." ; |
13 | roledefinition.BasePermissions = permissions; |
14 |
15 | OM.RoleDefinition role = context.Web.RoleDefinitions.Add(roledefinition); |
16 | context.ExecuteQuery(); |
17 |
18 | CreateGroup(role); |
19 | } |
20 | } |
01 | private void CreateGroup(OM.RoleDefinition roledefinition) |
02 | { |
03 | using (OM.ClientContext context = new OM.ClientContext(SPContext.Current.Site.Url)) |
04 | { |
05 | OM.GroupCreationInformation groupinfo = new OM.GroupCreationInformation(); |
06 | groupinfo.Description = "This is administrator group." ; |
07 | groupinfo.Title = "Administrator" ; |
08 | OM.Group group = context.Web.SiteGroups.Add(groupinfo); |
09 | OM.RoleDefinitionBindingCollection rdb = new OM.RoleDefinitionBindingCollection(context); |
10 | rdb.Add(roledefinition); |
11 | context.Web.RoleAssignments.Add(group, rdb); |
12 |
13 | context.ExecuteQuery(); |
14 | } |
15 | } |
Add the above code in FeatureActivated event.
1 | public override void FeatureActivated(SPFeatureReceiverProperties properties) |
2 | { |
3 | CreatePermission(); |
4 | } |
7. Browse to site permission and you will see new created group. Naviage to site permissions to check newly created permission for the site.
Browse the permission included in the newly created permission.
Newly created group
References :
SharePointing!!!!!!!
Comments