1

I would like to make a site collection read only programmatically. I used the

Site.ReadOnly = true

, but is not working. Now I would like to remove all the permissions on the root website of the site collection. After this I would like to give all authenticated user read permissions. As last I would like to ResetRoleInheritance for all websites, libraries, lists, items, documents etc. What is the best way to do that programmatically in c#?

1

I build this.

private void ResetRoleInheritance(SPSite site)
        {
            foreach (SPWeb website in site.AllWebs)
            {
                // Reset role inheritance, except root website
                if (website.HasUniqueRoleAssignments && !website.Url.Equals(site.Url))
                {
                    website.Update(); // TODO is this needed
                    website.ResetRoleInheritance();
                }

                // reset role inheritance on all lists, libraries, items, documents
                foreach (SPList list in website.Lists)
                {
                    if (list.HasUniqueRoleAssignments)
                    {
                        list.ResetRoleInheritance();
                    }

                    foreach (SPListItem item in list.Items)
                    {
                        if (item.HasUniqueRoleAssignments)
                        {
                            item.ResetRoleInheritance();
                        }
                    }
                }

                website.Dispose();
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.