Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to take a backup of sitecollection whenever user tried to delete it. I am using SiteDeleting(SPWebEventProperties properties) event for this. One constraint is, i need to cancel the delete if the user is not siteadmin. My question is, how to cancel the delete if the user is not site admin.

bool res = properties.Web.UserIsSiteAdmin();            
          if (res)
            {
//backup
            }
else
{
//cancel
}

i have already done with the backup part but need to know how to cancel the delete.

Thanks in advance!

share|improve this question
add comment

1 Answer

In your SPWebEventProperties you have a Cancel and an ErrorMessage property that you can use to cancel the event.

else
{
    properties.Cancel = true; // setting this will change Status property from Continue to Cancel-WithError
    properties.ErrorMessage = "You are not allowed to delete this site";
}

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spwebeventproperties_members(office.12).aspx

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.