fbpx

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;
 
//Code:
     SPSite site = new SPSite(SPContext.Current.Site.Url);
     SPWeb web = site.OpenWeb();
    if(web.HasUniqueRoleDefinitions || web.IsRootWeb)
    {
        try
        {
            web.AllowUnsafeUpdates = true;
            SPRoleDefinition roleDef = new SPRoleDefinition();
            roleDef.BasePermissions = SPBasePermissions.ManageLists | 
            SPBasePermissions.CancelCheckout |       
                 SPBasePermissions.AddListItems |
            SPBasePermissions.EditListItems |
            SPBasePermissions.DeleteListItems;
            roleDef.Name = "EblogIn Role";
           web.RoleDefinitions.Add(roleDef);
           web.Update();
  }
  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