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

1 Answer 1


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.

  • 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. Jan 11, 2013 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, 2013 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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