none
Handling list event. RRS feed

  • Question

  • I want to handle the event of my Document Library.
    I use the "SPEventReceiverDefinition" class to test the event of the list.
    It is worked.

    Then i deleted the assembly that i tested in previous.

    I create my new event class and update this assembly to eventreceivers of sharepoint.

    But it is still worked with the first assembly.

    I don't know why it is happened.

    Pls point me.
    Thursday, March 4, 2010 4:07 AM

Answers

  • I guess you did but just checking. Have you tried iisreset? It seems like it is still loaded in w3wp process.

    Thursday, March 4, 2010 12:13 PM

All replies

  • I guess you did but just checking. Have you tried iisreset? It seems like it is still loaded in w3wp process.

    Thursday, March 4, 2010 12:13 PM
  • Thanks for replying me.

    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
    Friday, March 5, 2010 2:38 AM
  • It seems context user does not have enough access right. Use SPSecurity.RunWithElevatedPrivileges which executes the specified method with Full Control rights even if the user does not otherwise have Full Control

    Try following syntax

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
    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();
    }
    Monday, March 8, 2010 1:09 PM