How to configure uniform Document Library settings for entire site collection in SharePoint Online


in ,

Recently, we finally migrated all our content to SharePoint Online (Office365). Microsoft really did a great job with their infrastructure and optimizations. SharePoint works great in the cloud.

When deploying our new intranet portal I defined the following rule for Document Libraries:

  • Each should be visible in Quick Launch
  • Major versions should be enabled

You can achieve this:

  • By manually configuring each document library (Please don’t.)
  • By creating a document library template with these settings (it will work, but if someone uses default template, it will not follow your guidelines)
  • By automating this via .NET code or PowerShell

For our internal use I developed a small C# app that uses SharePoint Client Object Model to configure the settings mentioned above. My friend Wictor Wilen has posted this great Office365 / SharePoint Online authentication library that saved me a lot of time.

The sample below will iterate your sites and update Document Library settings to match the rule I mentioned above. You will also need the library from Wictor.

Please note: I have no idea if this code is optimal. It might break your SharePoint. It worked well for our, English template based site collection.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;

namespace Acceleratio.Office365.DLUpdates {
    class Program {
        static void Main(string[] args) {

            Console.Write("SharePoint Online URL (e.g. ");
            string url = Console.ReadLine();
            Console.Write("Username (e.g. ");
            string username = Console.ReadLine();
            Console.Write("Password: ");
            string password = ReadPassword();

            // download here:
            Wictor.Office365.MsOnlineClaimsHelper claimsHelper = new Wictor.Office365.MsOnlineClaimsHelper(url, username, password);
            using (ClientContext context = new ClientContext(url))
                context.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;


                Console.WriteLine("Please wait while we update your site. This can take a while... Go for a run!");
                GetSubSites(context, context.Web);

        private static void GetSubSites(ClientContext context, Web web)
            Console.WriteLine("Updating {0}", web.ServerRelativeUrl);
            UpdateDocumentLibrarySettings(context, web);


            foreach(Web w in web.Webs)
                GetSubSites(context, w);

        private static void UpdateDocumentLibrarySettings(ClientContext context, Web web)

            ListCollection lists = web.Lists;
            foreach (List list in lists)
                context.Load(list, l => l.IsSiteAssetsLibrary);

                // Only non hidden, non system Document Libraries will be updated (update for different languages)
                if (!list.Hidden && !list.IsSiteAssetsLibrary && list.BaseType == BaseType.DocumentLibrary && list.Title != "Form Templates" && list.Title != "Style Library")
                    list.EnableVersioning = true;

                    // Site Pages lib will not be visible on Quick Launch (update for different languages)
                    if(list.Title != "Site Pages")
                        list.OnQuickLaunch = true;


        private static string ReadPassword()
            string pass = "";
            ConsoleKeyInfo key;

                key = Console.ReadKey(true);

                // Backspace Should Not Work
                if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
                    pass += key.KeyChar;
                    if (key.Key == ConsoleKey.Backspace && pass.Length > 0)
                        pass = pass.Substring(0, (pass.Length - 1));
                        Console.Write("\b \b");
            // Stops Receving Keys Once Enter is Pressed
            while (key.Key != ConsoleKey.Enter);


            return pass;


5 responses to “How to configure uniform Document Library settings for entire site collection in SharePoint Online”

  1. Nice sample but from time to time you have the script to run again. Hope that some day a provisioning handler for lists and libraryies exists too. 😉

  2. Toni Frankola Avatar
    Toni Frankola

    Yeah, not ideal. A centralized governance policies would be much better solution.

  3. Please note that the claims helper class will only work for https:// url. If you are trying to authenticate to your public website site collection you will get authentication errors.

  4. Toni Frankola Avatar
    Toni Frankola

    @Jose: Never tried that. However even public site should have an alternative URL like

  5. Do you know how to set this variable to true?
    In SP2013 has a get set method but apparently in SP online it only supports the get method.
    Thank you