In our SharePoint portal we have some custom views defined for list and libraries.

I have created the views using list event receiver. Now I need to disable the new/edit/delete views option from SharePoint so that no one can create, modify or delete the view for any of the lists.

How to achieve this? Any object model to achive this?


Creating custom permission level.

using (SPWeb currentSite = SPContext.Current.Site.RootWeb)
    // create a new role definition and set base permissions
    SPRoleDefinition roleDefinition = new SPRoleDefinition()
    Name = "Custom Permission Level",
    BasePermissions = SPBasePermissions.AddListItems | SPBasePermissions.OpenItems |
        SPBasePermissions.ViewListItems | SPBasePermissions.EditListItems

    // add the role definition


Using existing role definition:

public static void AddPrincipalRoleToSite(SPPrincipal entity, SPWeb web, string roleDef)
    SPRoleAssignment roleAssignment = new SPRoleAssignment(entity);
    SPRoleDefinitionCollection collRoles = web.RoleDefinitions;
    SPRoleDefinition oRoleDefinition = collRoles[roleDef];

| improve this answer | |
  • Thanks @Jussi Palo: Instead of creating new role definition is that possible to set this permission to the existing role definition? – TinTin Feb 21 '12 at 8:38
  • Updated answer. – Jussi Palo Feb 21 '12 at 9:08
  • Thanks @Jussi Palo: where we are using the role parameter, It seems there was some issue with this answer. – TinTin Feb 21 '12 at 13:26
  • Actually the role parameter might not be needed (not at my machine so cannot test). Removed the parameter. Can you post the error, if you get some. – Jussi Palo Feb 21 '12 at 14:29
  • Error :Permission level cannot be found. for this line i am getting the issue. "SPRoleDefinition oRoleDefinition = collRoles[roleDef];"SPRoleDefinition oRoleDefinition = collRoles[roleDef];" i am calling method like this "AddPrincipalRoleToSite(web.CurrentUser, SPRoleType.Contributor, web, "ManagePersonalViews");" – TinTin Feb 22 '12 at 5:51

I think that you should create your own role defenition based on SPBasePermissions enumeration, in this defenition you should exclude following base permissions:

  1. ManagePersonalViews - Create, change, and delete personal views of lists.
  2. ManageLists - Create and delete lists, add or remove columns in a list, and add or remove public views of a list.

Then you should assigne this role defenition to user group which contains users that should not create views.

| improve this answer | |
  • Do u have any coding sample for this?. Thanks in advance – TinTin Feb 21 '12 at 6:57
  • for defenition creation you can look at first post that I provided. Do you need example how to assigne a new defenition to a user group by code? – Alexander Feb 21 '12 at 7:15
  • my problem i have some set of cusomized user and group permission, so i am not able to create new user or role.Atleast i can remove the view related permisson from the site for all the user in the site. Is that possible to do. – TinTin Feb 21 '12 at 7:22
  • you can break role inheritance only for your list, and configure groups in this list as you wish. These changes are not affected to other site and lists permissions. – Alexander Feb 21 '12 at 8:07
  • :Don't we have option to remove the "ManagePersonalViews" permission from contributer(OOB)? – TinTin Feb 22 '12 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.