Вопрос

We have a specific business need where we need to allow users to be able to create Wiki Page in a Wiki Library but restrict them from adding web parts to a Wiki Page. If we provide a user to contribute access to the Wiki Library, the user is able to add web part by clicking on Insert and add an existing web part.

Does anyone know anyway to have the user be able to contribute to the content of the page by editing it, but not add web parts to the page?

Thanks

Это было полезно?

Решение

If you can add custom code you could create an event receiver feature for the list item ItemUpdating event for the wiki in order to check for the presence of a web part and cancel the save and display a message.

Event receivers for lists will fire for all lists based on a template (so in your case all wiki libraries) if you only want this to operate on an individual instance then modify the sample code below to check for the wiki library instance you want to control.

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
            }
        }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top