1

I got a lot of sites with document libraries where the "Make "New Folder" command available" option is set to "no". I would like to walk through these document libraries and change this to "yes". How can I achieve this? After doing some search, I found that a lot of things can be done with the files in a document library, but did not find any example that shows how to change settings (advanced settings) of the library itself.

Thank you, vm

vilmarci
  • 451
  • 10
  • 31

2 Answers2

1

Using powershell.

$list.EnableFolderCreation = $true;
$list.update();

put this inside a for loop that iterates through the lists/sites/webs of your farm. something like:

$sc = http://myweb.com/mysitecollection
$spsite = Get-SPsite $sc 

foreach ($web in $spsite.AllWebs)
{   

    foreach ($list in $web.Lists)
    {
        $list.EnableFolderCreation = $true;
        $list.update();
    }
}
$spsite.dispose()

if you would rather do this using the client object model, throw this into a console app. (make sure you reference Microsoft.SharePoint.dll)

using System;
using Microsoft.SharePoint;

namespace SharepointModifier
{
    class FolderEnabler
    {
        static void Main(string[] args)
        {

            string sitecollectionaddress = "Http://mysitecollection.com/";

            using (SPSite mysites = new SPSite(sitecollectionaddress))
            {
                foreach (SPWeb web in mysites.AllWebs)
                {
                    foreach (SPList list in web.Lists)
                    {
                        list.EnableFolderCreation = true;
                        //Make any other changes to list properties here
                        list.Update();
                        Console.WriteLine(list.Title + " Has been updated.");    
                    }
                }
            }

        }
    }
}
Nikerym
  • 515
  • 3
  • 12
  • Thank you. I will convert the code to vb and test it. So... seems like I should handle a document library as a list. – vilmarci Sep 08 '15 at 07:18
1

Since you are looking for solution that utilizes CSOM API, the below example demonstrates how enable folders for document libraries:

using (var ctx = new ClientContext(webUri))
{ 
    var result = ctx.LoadQuery(ctx.Web.Lists.Where(l => l.BaseType == BaseType.DocumentLibrary && !l.Hidden));
    ctx.ExecuteQuery();
    foreach (var list in result)
    {
        list.EnableFolderCreation = true;
        list.Update();
    }
    ctx.ExecuteQuery(); 
}

VB.Net version

Using context As Microsoft.SharePoint.Client.ClientContext = New Microsoft.SharePoint.Client.ClientContext(webUri)
        Dim qry = From l In context.Web.Lists
            Where (CInt(l.BaseType) = 1) AndAlso Not l.Hidden
            Select l
        Dim result As IEnumerable(Of Microsoft.SharePoint.Client.List) = context.LoadQuery(qry)
        context.ExecuteQuery()
        Dim list As Microsoft.SharePoint.Client.List
        For Each list In result
            list.EnableFolderCreation = True
            list.Update()
        Next
        context.ExecuteQuery()

    End Using
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • Thank you. Could you please tell me how to translate this part to vb? 'var result = ctx.LoadQuery(ctx.Web.Lists.Where(l => l.BaseType == BaseType.DocumentLibrary && !l.Hidden));' I tried converters but this: 'Dim result = ctx.LoadQuery(ctx.Web.Lists.Where(Function(l) l.BaseType = BaseType.DocumentLibrary AndAlso Not l.Hidden))' throws this exception: The expression ((ConvertChecked(l.BaseType) == 1) AndAlso Not(l.Hidden)) is not supported. I think, I know what it is doing and finally ended up with a working code by checking the list basetype later. Thank you again, vm – – vilmarci Sep 10 '15 at 14:12
  • @vilmarci, see the updated answer with Vb.Net example – Vadim Gremyachev Sep 10 '15 at 14:36