Adding “Everyone” Permissions Programmatically in SharePoint 2013

Ever needed to add permissions to a list for “Everyone” in code, but nothing worked? Not NT Authenticated Users, not All Users?  Turns out, it’s super simple if you know the completely obscure account name for “Everyone”.

SPUser allUsers = web.AllUsers[@”c:0(.s|true”];
SPRoleDefinitionCollection roleCollection = web.RoleDefinitions;
SPRoleDefinition roleDefinition = roleCollection[“Contribute”];

SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)allUsers);


// save

Because why wouldn’t the account name for “Everyone” be “c:o(.s|true”?


2 thoughts on “Adding “Everyone” Permissions Programmatically in SharePoint 2013

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s