4

I want to perform some Action once the item is added. I have a Custom List that reacts on Item Creation.

If, at this level, i want to Delete the item immediately once it is added, how could I do?

Thank you very much!

3 Answers 3

2

You can use sharepoint designer to create a list workflow for the list.

You can use conditions to determine if the item should be deleted.

Then you can delete the current item.

2

As C.Marius mentions, if you are able to add custom code, go for a Event Handler.

To point you in the right direction, check this example out;

http://msdn.microsoft.com/en-us/library/ms437502(v=office.14).aspx

But would it not be better to prevent users to add the listitem in the first place?

Anyway, the most simple approach i can think off:

Public override void ItemAdded(SPItemEventProperties properties)
{
    base.ItemAdded(properties);

    properties.ListItem.Delete();
    properties.Cancel = true;
}

And dont forget to scope the Event Handler to the specific list in the Elements.xml, just change

<Receivers ListTemplateId="100"> 

to this

<Receivers ListUrl="Lists/someListName"> 
1

It will depend on the intended approach:

  1. By code - you always have Event Handlers (OnItemAdding - synchronous, which can be cancelled if a certain condition is not met or OnItemAdded - asynchronous - if you wish to perform some stuff prior to deleting it, that triggers after the actual item has been created). Great advantage of a handler is that you could tie that into a content type, certain list type - which increase reusability
  2. As Russell already mentioned, more declarative, for special cases, or if you are rather targeting Content types - a Reusable workflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.