Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

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.

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

 
discard

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.