Skip to main content
added 93 characters in body
Source Link
sssreddy
  • 4.5k
  • 2
  • 22
  • 38

You can do something like this

                SPWeb web = site.RootWeb;
                web.AllowUnsafeUpdates = true;
                SPList list = web.Lists["Test1"];

                SPUser allusers = web.EnsureUser("NT AUTHORITY\\authenticated users");
                SPRoleAssignment role = new SPRoleAssignment(allusers);
                SPRoleDefinition def = web.RoleDefinitions.GetByType(SPRoleType.Reader);
                role.RoleDefinitionBindings.Add(def);

                if (!list.HasUniqueRoleAssignments)
                {
                    list.BreakRoleInheritance(false);
                }
                list.RoleAssignments.Add(role);
                list.Update();

                web.AllowUnsafeUpdates = false;

To reset permissions use

            list.ResetRoleInheritance();
            list.Update();

Also you need to take into consideration, if the list already has UniqueRoleAssignments.

You can do something like this

                SPWeb web = site.RootWeb;
                web.AllowUnsafeUpdates = true;
                SPList list = web.Lists["Test1"];

                SPUser allusers = web.EnsureUser("NT AUTHORITY\\authenticated users");
                SPRoleAssignment role = new SPRoleAssignment(allusers);
                SPRoleDefinition def = web.RoleDefinitions.GetByType(SPRoleType.Reader);
                role.RoleDefinitionBindings.Add(def);

                if (!list.HasUniqueRoleAssignments)
                {
                    list.BreakRoleInheritance(false);
                }
                list.RoleAssignments.Add(role);
                list.Update();

                web.AllowUnsafeUpdates = false;

To reset permissions use

            list.ResetRoleInheritance();
            list.Update();

You can do something like this

                SPWeb web = site.RootWeb;
                web.AllowUnsafeUpdates = true;
                SPList list = web.Lists["Test1"];

                SPUser allusers = web.EnsureUser("NT AUTHORITY\\authenticated users");
                SPRoleAssignment role = new SPRoleAssignment(allusers);
                SPRoleDefinition def = web.RoleDefinitions.GetByType(SPRoleType.Reader);
                role.RoleDefinitionBindings.Add(def);

                if (!list.HasUniqueRoleAssignments)
                {
                    list.BreakRoleInheritance(false);
                }
                list.RoleAssignments.Add(role);
                list.Update();

                web.AllowUnsafeUpdates = false;

To reset permissions use

            list.ResetRoleInheritance();
            list.Update();

Also you need to take into consideration, if the list already has UniqueRoleAssignments.

Source Link
sssreddy
  • 4.5k
  • 2
  • 22
  • 38

You can do something like this

                SPWeb web = site.RootWeb;
                web.AllowUnsafeUpdates = true;
                SPList list = web.Lists["Test1"];

                SPUser allusers = web.EnsureUser("NT AUTHORITY\\authenticated users");
                SPRoleAssignment role = new SPRoleAssignment(allusers);
                SPRoleDefinition def = web.RoleDefinitions.GetByType(SPRoleType.Reader);
                role.RoleDefinitionBindings.Add(def);

                if (!list.HasUniqueRoleAssignments)
                {
                    list.BreakRoleInheritance(false);
                }
                list.RoleAssignments.Add(role);
                list.Update();

                web.AllowUnsafeUpdates = false;

To reset permissions use

            list.ResetRoleInheritance();
            list.Update();