【问题标题】:SharePoint 2010 Wiki Page Library - Restrict Inserting Web Part in a Wiki PageSharePoint 2010 Wiki 页面库 - 限制在 Wiki 页面中插入 Web 部件
【发布时间】:2023-03-11 11:39:01
【问题描述】:
我们有一个特定的业务需求,我们需要允许用户能够在 Wiki 库中创建 Wiki 页面,但限制他们将 Web 部件添加到 Wiki 页面。如果我们为用户提供对 Wiki 库的贡献访问权限,则用户可以通过单击“插入”来添加 Web 部件并添加现有的 Web 部件。
是否有人知道让用户能够通过编辑页面内容来为页面内容做出贡献,但不能向页面添加 Web 部件?
谢谢
【问题讨论】:
标签:
sharepoint
sharepoint-2010
wiki
sharepoint-wiki
【解决方案1】:
如果您可以添加自定义代码,您可以为 wiki 的列表项 ItemUpdating 事件创建事件接收器功能,以检查 Web 部件是否存在并取消保存并显示消息。
如果您只想对单个实例进行操作,则列表的事件接收器将为基于模板的所有列表(因此在您的情况下为所有 wiki 库)触发,然后修改下面的示例代码以检查您的 wiki 库实例想要控制。
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
SPListItem item = properties.ListItem; //get the list item being updated
string pageUrl = item.Url; //get the item url for the web part manager
SPLimitedWebPartManager lwpm = properties.Web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared); //get the web part manager
if (lwpm.WebParts.Count > 0) //test for the presence of any web parts
{
properties.Cancel = true; //cancel the save
properties.ErrorMessage = "WebParts are not allowed on this wiki page."; //display message to the user
}
}