SharePoint 2010 create permission level with Add but no View permission using API
I have a scenario where I want to give users initialy only the ability to create items in开发者_开发百科 a list and explicitly give them no view items permission. I will provide them with their own add button (outside the list) and only give them read permission on the list after the creation using a workflow.
What I essentially need thus, is a permission level with additems permission, but not viewitems. Using the UI this permission level cannot be created. Has anyone tried doing this using the API? (I'm quite sure this was possible in previous versions of SharePoint)
This describes a solution to your problem
I think it should give you the information you need.
Yup, it's a bitmask using the SPBasePermissions enumeration. And this code works perfectly well in 2007 or 2010.
E.g. Set up your bit mask by ORing all the bits.
SPBasePermissions perms = SPBasePermissions.AddListItems |
SPBasePermissions.EditListItems |
SPBasePermissions.ViewListItems |
SPBasePermissions.OpenItems |
...
And then create a new role:
SPRoleDefinition roleDefinition = new SPRoleDefinition();
roleDefinition.Name = "New Role Name";
roleDefinition.Description = "Description";
roleDefinition.BasePermissions = perms;
web.AllowUnsafeUpdates = true;
web.RoleDefinitions.Add(roleDefinition);
web.AllowUnsafeUpdates = false;
精彩评论