If you have many sites under a web application, there will be a situation when you need to use the custom permission for a particular site. Some time you inherit the roles and sometime not. You can create custom permission level programmatically.

You can only create new role (permission level) at site collection level, and then you can use this role in sub sites.

Here is the code to create new permission level.

Add assembly reference:

using Microsoft.SharePoint;
     SPSite site = new SPSite(SPContext.Current.Site.Url);
     SPWeb web = site.OpenWeb();
    if(web.HasUniqueRoleDefinitions || web.IsRootWeb)
            web.AllowUnsafeUpdates = true;
            SPRoleDefinition roleDef = new SPRoleDefinition();
            roleDef.BasePermissions = SPBasePermissions.ManageLists | 
            SPBasePermissions.CancelCheckout |       
                 SPBasePermissions.AddListItems |
            SPBasePermissions.EditListItems |
            roleDef.Name = "EblogIn Role";
  catch (Exception ex) { }

1 Comment

Comments are closed.

About Us

Follow Us

Email: contact@keapoint.com
Phone:  0208 7852 888

Registered Address: 1 Amber Close, Reading, RG6 7ED. United Kingdom

Company No. 11586817