I have created a console application in which I have defined ItemAdded
event receiver method. I wanted to know how to execute the ItemAdded
method, do I need to call this method inside the Main
function? If yes, then how?
Here is my code
class Program : SPItemEventReceiver
{
static void Main(string[] args)
{
Program pgm = new Program();
}
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
base.ItemAdded(properties);
SPSite site = new SPSite("http://cdcgtdevvm258/sites/amit/dummy");
SPWeb web = site.RootWeb;
SPList list = web.Lists[""];
SPListItem listitem = properties.List.AddItem();
listitem["Title"] = "Example";
listitem.Update();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}