Skip to main content
Removed code indenting
Source Link
Kit Menke
  • 4.2k
  • 6
  • 32
  • 40

The easiest way to invoke some code on submission (...insert) of a list item it to write an ItemAdded event receiver. The item level event receiver can be registered against a web, list or content type. Here's an example of registering one against a web (...this would fire for an item added to any list or library on the web:

            SPEventReceiverDefinition itemAdded = web.EventReceivers.Add();
            itemAdded.Type = SPEventReceiverType.ItemAdded;
            itemAdded.Assembly = "MyAssemly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=141fe4b547d7494f";
            itemAdded.Class = "MyClass";
            itemAdded.SequenceNumber = 100;
            itemAdded.Update();

And then the event receiver would look something like this:

public class EventReceivers : SPItemEventReceiver
{
    public override void ItemAdded(SPItemEventProperties properties)
    {
       // perform ItemAdded operation
    }
}

The easiest way to invoke some code on submission (...insert) of a list item it to write an ItemAdded event receiver. The item level event receiver can be registered against a web, list or content type. Here's an example of registering one against a web (...this would fire for an item added to any list or library on the web:

            SPEventReceiverDefinition itemAdded = web.EventReceivers.Add();
            itemAdded.Type = SPEventReceiverType.ItemAdded;
            itemAdded.Assembly = "MyAssemly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=141fe4b547d7494f";
            itemAdded.Class = "MyClass";
            itemAdded.SequenceNumber = 100;
            itemAdded.Update();

And then the event receiver would look something like this:

public class EventReceivers : SPItemEventReceiver
{
    public override void ItemAdded(SPItemEventProperties properties)
    {
       // perform ItemAdded operation
    }
}

The easiest way to invoke some code on submission (...insert) of a list item it to write an ItemAdded event receiver. The item level event receiver can be registered against a web, list or content type. Here's an example of registering one against a web (...this would fire for an item added to any list or library on the web:

SPEventReceiverDefinition itemAdded = web.EventReceivers.Add();
itemAdded.Type = SPEventReceiverType.ItemAdded;
itemAdded.Assembly = "MyAssemly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=141fe4b547d7494f";
itemAdded.Class = "MyClass";
itemAdded.SequenceNumber = 100;
itemAdded.Update();

And then the event receiver would look something like this:

public class EventReceivers : SPItemEventReceiver
{
    public override void ItemAdded(SPItemEventProperties properties)
    {
       // perform ItemAdded operation
    }
}
Source Link
Rob D'Oria
  • 5k
  • 18
  • 16

The easiest way to invoke some code on submission (...insert) of a list item it to write an ItemAdded event receiver. The item level event receiver can be registered against a web, list or content type. Here's an example of registering one against a web (...this would fire for an item added to any list or library on the web:

            SPEventReceiverDefinition itemAdded = web.EventReceivers.Add();
            itemAdded.Type = SPEventReceiverType.ItemAdded;
            itemAdded.Assembly = "MyAssemly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=141fe4b547d7494f";
            itemAdded.Class = "MyClass";
            itemAdded.SequenceNumber = 100;
            itemAdded.Update();

And then the event receiver would look something like this:

public class EventReceivers : SPItemEventReceiver
{
    public override void ItemAdded(SPItemEventProperties properties)
    {
       // perform ItemAdded operation
    }
}