Sunday, September 21, 2014

Set Owner for a Group in SharePoint site programmatically

Introduction

As all we know, We have an option to keep group with set of people in SharePoint. This group is having some permission to access the site. Generally, We have three groups in a site like Owner, Contributor and Visitor. Owners having rights to do all in site. Contributor is allowing to access the site with limited permission. Visitor is having rights to just visit a site.
We may set an owner to these groups. By default, It will take Site Collection admin as an Owner of the group. Let us see how to modify that programmatically.

Customization

var groupName = SPContext.Current.Web.Groups["YourGroupName"];
groupName.Owner = "UserName"; //Give as SPUser
groupName.Update();
SPContext.Current.Web.Update();

That's all group owner has set to the group.

No comments:

Post a Comment