SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is Sample of my Code

SPList list = new SPSite(siteURL).OpenWeb().Lists[listName]; SPEventReceiverDefinitionCollection eventReceivers = list.EventReceivers;

SPEventReceiverDefinition eventReceiver = eventReceivers.Add();

but when i use this code it returns error while Build Project and error is

Error 1 'Microsoft.SharePoint.SPEventReceiverDefinitionCollection' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'Microsoft.SharePoint.SPEventReceiverDefinitionCollection' could be found (are you missing a using directive or an assembly reference?)

The Error is in line eventReceivers.Add(); What Should I do now? can anybody help me Its Urgent.. Its a Sandboxed Solution..

share|improve this question

If you have no restrictions then change scope of your project from Sandboxed to Farm. It will work. I have the same Problem and I got the solution after I changed the Scope.

share|improve this answer
If you found this answer helpful then don't forget to mark as answer. So that if someone else get this problem can get the solution. – Torque Jan 11 '13 at 5:41
I cant change the scope from sandbox to farm . as i want this solution to work with office 365. And office 365 only need Sandbox solutions. ;( – Gaurav Jan 11 '13 at 6:05

Your Answer


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.