I have a another problem.I did above testing in my own computer.
When i really do to my site, the following error is occured.
First i install my assembly that contains my event class to the GAC.
I use the following code to add event to document library.
SPSite l_SPSite = new SPSite("http://mysharepointsite");
SPWeb l_SPWeb = l_SPSite.OpenWeb();
SPList l_SPList = l_SPWeb.Lists["Documents"];
string id = l_SPList.ID.ToString();
SPEventReceiverDefinition l_SPEvent = l_SPList.EventReceivers.Add();
l_SPEvent.Class = "ItemPermission.SPDocumentEventHandler";
l_SPEvent.Assembly = "ItemPermission,Version=1.0.0.0,Culture=neutral,PublicKeyToken=123770469bc80c2b";
l_SPEvent.SequenceNumber = 5000;
l_SPEvent.Type = SPEventReceiverType.ItemAdded;
l_SPEvent.Name = "CustomAddingEvent";
l_SPEvent.Update();//Error is happened here.
Error is :
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Thanks
Loading
Raaj KumarPosted Mar 5, 2010, 12:08 AM
It looks like privilege problem. Make sure the user has sufficient privilege.
For more information please have a look at the following links,
http://blogs.msdn.com/brianwilson/archive/2007/03/18/event-handlers-part-3-register-event-handlers-plus-free-site-settings-manage-event-handlers-add-on.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverdefinition.aspx
Regards,
raaj