Add groups using Client object model SharePoint 2010

Create a User Group –

//get the connection

ClientContext ctx = new ClientContext(“http://SPSite”);

//create the group

GroupCreationInformation grp = new GroupCreationInformation();

grp .Title = “Your New Group”;

grp .Description = “This is a custom group created using the client object model”;

//add it to the list of site groups

Group newgrp = ctx.Web.SiteGroups.Add(grp);

//Get a role.

RoleDefinition rd = ctx.Web.RoleDefinitions.GetByName(“Permission level Name”); // – > To Create a Custom Role definition or Permission level see my post Here

//create the role definition binding collection

RoleDefinitionBindingCollection rdb = new RoleDefinitionBindingCollection(ctx);

//add the role definition to the collection

rdb.Add(rd);

//create a RoleAssigment with the group and role definition

ctx.Web.RoleAssignments.Add(grp, rdb);

//execute the query to add everything

ctx.ExecuteQuery();

0 comments:

Post a Comment

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com