This can be done in either below three ways
- Deploy programmatically through code
- Using STSADM command ( SharePoint Feature)
- Using content types
Let’s see how to deploy using code. This method is not suitable when you are working in Development life cycle. Best practice is to create a Feature and deploy that to your production server and you are good. But for illustration purpose lets see the code way!!!
In my previous post we created simple Event Log event receiver which logs the user entries in a text file. Lets deploy the same Event Receiver.
Console Application for Deploying Event Receiver:
static void Main(string args)
SPSite spsite = new SPSite("http://SharePointForFun:555/");
SPWeb mysite = spsite.OpenWeb();
SPList theList = mysite.Lists["EventLog"];
SPEventReceiverDefinition newReceiver = theList.EventReceivers.Add();
newReceiver.Class = "EventLog.LogEvent ";
newReceiver.Assembly = "EventLog",
newReceiver.SequenceNumber = 5055;
newReceiver.Type = SPEventReceiverType.ItemAdded;
That's it. Once you run this console application Event gets deployed to the SharePoint server defined in the SPSite object. Have Fun with SharePoint.