Hi,
I want to trap items in a list being deleted and stop it.
I can do this easily and all works well... but now I want to check to see if the current user is a member of an owners group.
If they are then allow delete, if not then trap and cancel the event.
My account is a member of the owner group and can delete no problem.
However I have logged on as a user who has contribute but is not in the owners group and can still delete.
Is there a problem with my logic or have I missed something?
public override void ItemDeleting(SPItemEventProperties properties)
{
base.ItemDeleting(properties);
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
int _currentUser = properties.CurrentUserId;
SPUser spCurrentUser = web.AllUsers[_currentUser];
SPGroup ownerGroup = web.Groups["Sandpit Owners"];
if (spCurrentUser.Groups[ownerGroup.ID] != null)
{
properties.Cancel = true;
properties.ErrorMessage = "Deleting announcements is not allowed!";
}
else
{
properties.Cancel = false;
properties.Status = SPEventReceiverStatus.Continue;
}
}
}