SharePoint 2010 禁用列表或文档库新建文件夹命令的三种方法

本文详细介绍了如何通过Feature和C#代码在SharePoint中隐藏新建文件夹命令,包括针对列表和文档库的两种实现方式。通过修改自定义操作ID和位置属性,可以实现在不同上下文中禁用新建文件夹功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1.通过Feature来实现

1.1如果你想针对列表来隐藏新建文件夹命令,Feature代码如下:

<CustomAction Id="Remove.ListItem.NewFolder" Location="CommandUI.Ribbon"> <CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location="Ribbon.ListItem.New.NewFolder" /> </CommandUIDefinitions> </CommandUIExtension> </CustomAction> 

1.2如果你想针对文档库来隐藏新建文件夹命令,Feature如下:

<CustomAction Id="Remove.Document.NewFolderButton" Location="CommandUI.Ribbon" RegistrationId="0x0101" RegistrationType="ContentType"> <CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location="Ribbon.Documents.New.NewFolder" /> </CommandUIDefinitions> </CommandUIExtension> </CustomAction>

1.3如果你想同时针对列表和文档库 来隐藏新建文件夹命令,Feature如下:

<?xmlversion="1.0"encoding="utf-8"?> <Elementsxmlns="http://schemas.microsoft.com/sharepoint/"> <CustomAction Id="Remove.ListItem.NewFolder" Location="CommandUI.Ribbon"> <CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location="Ribbon.ListItem.New.NewFolder"/> </CommandUIDefinitions> </CommandUIExtension> </CustomAction> <CustomAction Id="Remove.Document.NewFolderButton" Location="CommandUI.Ribbon"RegistrationId="0x0101" RegistrationType="ContentType"> <CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location="Ribbon.Documents.New.NewFolder"/> </CommandUIDefinitions> </CommandUIExtension> </CustomAction> </Elements>

2.通过c#代码来实现:

无论是列表还是文档库都有一个.EnableFolderCreation 属性,它可以控制是否启用新建文件夹命令。

SPSite spSite = new SPSite("http://sp2010vm"); foreach (SPWeb spWeb in spSite.AllWebs) { spWeb.AllowUnsafeUpdates = true; SPListCollection lists = spWeb.Lists; for (int i = 0; i < lists.Count; i++) { if (lists[i] is SPDocumentLibrary) { if (((SPDocumentLibrary)lists[i]).IsCatalog == false) { SPDocumentLibrary spList = (SPDocumentLibrary)lists[i]; if (spList.Title == "Classified Documents") { ////Update the list properties spList.EnableFolderCreation = false; spList.Update(); } } } } spWeb.AllowUnsafeUpdates = false; spWeb.Dispose(); } spSite.Dispose();


3.库设置--高级设置--     是否提供“新建文件夹”命令

列表设置--高级设置--     是否提供“新建文件夹”命令



转载于:https://www.cnblogs.com/-shadow/archive/2011/10/17/2215445.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值