Naveen
Naveen

Reputation: 53

How to add Azure AD group to SharePoint programmatically using c#

How can I add a Azure AD group to a SharePoint Online site collection administrators through a console application.

Upvotes: 0

Views: 685

Answers (1)

Lee
Lee

Reputation: 5493

My sample tested code, you may try it. TestSecurityGroup is an Azure AD security group.

Web web = clientContext.Web;
                var SPGroup = web.SiteGroups.GetById(7);
                User group = clientContext.Web.EnsureUser("TestSecurityGroup");
                clientContext.Load(group);
                User addUser=SPGroup.Users.AddUser(group);
                clientContext.Load(addUser);
                clientContext.ExecuteQuery();

Upvotes: 2

Related Questions