January 2011 Entries

How to assign an exiting SharePoint group to a site using the SharePoint object model?

The below code demonstrates how you can assign a SharePoint Group to a SharePoint site using the SharePoint object model. SPSite spsite = new SPSite("Site_Name"); try { using (SPWeb web = spsite.OpenWeb()) { web.AllowUnsafeUpdates = true; SPGroup sgrp = web.SiteGroups["Group_Name"]; SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByTy... SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincip... roleAssignment.RoleDefiniti... ......