Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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
    currentSite.RoleDefinitions.Add(roleDefinition);
}

Source.

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];

    roleAssignment.RoleDefinitionBindings.Add(oRoleDefinition);
    web.RoleAssignments.Add(roleAssignment);
}
share|improve this answer
    
Thanks @Jussi Palo: Instead of creating new role definition is that possible to set this permission to the existing role definition? –  MarsMan 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. –  MarsMan 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");" –  MarsMan Feb 22 '12 at 5:51
show 1 more comment

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.

share|improve this answer
    
Do u have any coding sample for this?. Thanks in advance –  MarsMan 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. –  MarsMan 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)? –  MarsMan Feb 22 '12 at 6:26
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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