Monday, September 22, 2008

Adding users/ groups to sharepoint web

Scenario:
You want to add certain users/group as a part of site creation.

SPWeb web = SPContext.Current.Web;

SPRoleDefinition role = site.RoleDefinitions["Contribute"];

// Adding User Groups

SPRoleAssignment roleAssignmentGroup;

roleAssignmentGroup = new SPRoleAssignment(@"Training\ConsumerGroup","consumers@training.com","All Consumers of the website","Notes about Consumer Group");

roleAssignmentGroup.RoleDefinitionBindings.Add(role);

web.RoleAssignments.Add(roleAssignmentGroup);

// Adding specific users

SPRoleAssignment roleAssignmentUser;

roleAssignmentUser = new SPRoleAssignment(@"TRAINING\SandeepK","sandeep@training.com","Sandeep Nahta","Notes:SharePoint Consultant");

roleAssignmentUser.RoleDefinitionBindings.Add(role);

web.RoleAssignments.Add(roleAssignmentUser);
Usage:
Provisioning Feature Activation , Console Application

0 comments: