更改 "Make "新建文件夹命令可用吗? Sharepoint 客户端对象模型的选项

Change the "Make "New Folder" command available?" option with Sharepoint Client Object Model

我有很多带有文档库的站点,其中 "Make "新文件夹“命令可用”选项设置为 "no"。 我想遍历这些文档库并将其更改为 "yes"。 我怎样才能做到这一点?经过一些搜索,我发现可以用文档库中的文件做很多事情,但没有找到任何说明如何更改库本身的设置(高级设置)的示例。

谢谢, 虚拟机

使用 powershell。

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

将它放在循环遍历您农场的 lists/sites/webs 的 for 循环中。类似于:

$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()

如果您更愿意使用客户端对象模型执行此操作,请将其放入控制台应用程序中。 (确保你引用 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.");    
                    }
                }
            }

        }
    }
}

由于您正在寻找利用 CSOM API 的解决方案,以下示例演示了如何为文档库启用文件夹:

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版本

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