Programmatically add permissions to “everyone” in SharePoint Online

Oct 7, 2015

At some point you may want to add permissions to the “everyone” “groupe” of SharePoint.

Indeed this will allow you to set permissions to all users already having access to this site (because they are already members of other groups or already have permissions). This “group” is different of “NT AUTHORITY\authenticated users » which represents successfully identified users (bigger group).

The only thing is that “group” is in fact a user, so it’s helpless to iterate on every group of the site collection hoping to find it. It’s in fact a special user. To find it just use it’s login: “c:0(.s|true”

Here is a CSOM example on how to do that

var user = item.ParentList.ParentWeb.EnsureUser("c:0(.s|true");
var roleBindings = new RoleDefinitionBindingCollection(context);
roleBindings.Add(item.ParentList.ParentWeb.RoleDefinitions.GetByType(roleType));
item.RoleAssignments.Add(principal, roleBindings);
context.ExecuteQuery();

Last edited Sep 6, 2021 by Vincent


Tags: