Restrict the delete option from Document Library in sharepoint 2010


public override void ItemDeleting(SPItemEventProperties properties)
{
    using(SPSite site = new SPSite(properties.SiteId))
    {
        using(SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
        { 
         
            if(properties["Title"] == "SomeTitle")
               return;

            properties.Cancel = true;
            properties.ErrorMessage = "You cannot delete item";
        }
    }
}

Comments

Popular posts from this blog

This content database has a schema version which is not supported in this farm

Export all documents/Folders permissions to CSV using SharePoint PowerShell

SPUtility.js