1

I have a list with multiple items. I don't want the user to delete the list when there are items with running workflows. I'm trying to avoid orphaned workflows and get more control over what the user is allowed to do with data in lists.

I've already implemented a part which denies the user to delete a single item with a running workflow by implementing ItemDeleting

/// <summary>
/// Synchronous before event that occurs before an existing item is completely deleted.
/// Business logic related to deleting items. Checks if there are any problems with deleting the list item.
/// If there are any problems with deleting then the event will be cancelled with an error message. Otherwise deletion is allowed
/// </summary>
/// <param name="properties">
/// A Microsoft.SharePoint.SPItemEventProperties object that represents properties of the event handler.
/// </param>
public override void ItemDeleting(SPItemEventProperties properties)
{
    SPListItem listItem = properties.ListItem;
    foreach (SPWorkflow workflow in listItem.Workflows)
    {
        if (workflow.InternalState == SPWorkflowState.Running)
        {
            properties.Cancel = true;
            properties.ErrorMessage = "It is not allowed to delete items with running workflows. Complete them before deleting";
        }
     }
 }

Now I want to do the same with the list itself, but there is no SPEventReceiverType available to accomplish my task. I've been googling around a little bit, but no luck.

Has anyone done this for Sharepoint 2007?

armannvg
  • 1,736
  • 1
  • 15
  • 29
  • I won't post this as an answer, because it's really just brainstorming: This may be unacceptable in your current circumstance, and doesn't address the root problem; however, revoking your users' Manage Lists permission on the individual list is enough to prevent it from being deleted. Of course, this is useless if they need manage lists permissions to do anything else on the list, such as add/configure columns. SharePoint 2010 has support for event receivers with a ListDeleting method, but that doesn't help those of us using 2007. – kbrimington Jul 30 '10 at 00:04
  • The result was just as you suggested, manipulating list permissions for 2007 and then implement it in the 2010 solution using the new event receivers. Post this as an answer and i'll mark it as correct :) – armannvg Nov 29 '10 at 16:02

0 Answers0