SharePoint 2013 - SPLessons

How to programmatically create a custom...

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

How to programmatically create a custom permission level in sharepoint

How to programmatically create a custom permission level in sharepoint

Description :

Hello Everyone, In our current post we are going to see how to programmatically create a custom permission level in sharepoint.

 

The below snippet is self explanatory.

[csharp]
public void CreateCustomPermissionLevel()
{
try
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
SPRoleDefinition role = new SPRoleDefinition();
role.Name = "AddEdit";
role.Description = "Description: Custom Permission level";
role.BasePermissions =
SPBasePermissions.AddAndCustomizePages |
SPBasePermissions.ApplyStyleSheets |
SPBasePermissions.AddListItems |
SPBasePermissions.EditListItems |
SPBasePermissions.ViewListItems |
SPBasePermissions.OpenItems |
SPBasePermissions.ViewVersions |
SPBasePermissions.CreateAlerts |
SPBasePermissions.ViewPages;
web.RoleDefinitions.Add(role);
}
}
}
catch (Exception ex)
{
// Error Logging
}
}
[/csharp]

Comments