简体   繁体   中英

How to prevent a SharePoint site collection from being deleted?

I am currently using Sharepoint 2010 admin web service and want to be sure that a specific site collection cannot be deleted. Does anyone know of a way to make this happen such that if I have a call like

adminService.DeleteSite(SiteCollection_TO_NEVER_DELETE);

Would never be removed?

Thanks for any suggestions

If I understand you correctly, it can be done by using a SharePoint Feature.

You can create and deploy a SharePoint Feature which has a web event receiver. In this event receiver you can override the SiteDeleting method and cancel the request to delete a site collection by changing the value of the property Cancel of the parameter to true . This would return an error for anyone trying to delete the site collection. You can also add an error message.

For example:

    /// <summary>
    /// A site collection is being deleted
    /// </summary>
    public override void SiteDeleting(SPWebEventProperties properties)
    {
        base.SiteDeleting(properties);
        if(/*some condition*/)
        { 
            properties.Cancel = true;
            properties.ErrorMessage = "This site collection should never be deleted.";
        }
     }

You can check for a specific name or a specific URL.

Of course, it would still be possible to deactivate the feature and still delete the site. But at least it would prevent it from being deleted accidentally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM