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 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!

share|improve this question
add comment

3 Answers

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"> 
share|improve this answer
add comment

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.

share|improve this answer
add comment

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.
share|improve this answer
add comment

Your Answer

 
discard

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

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