none
Sharepoint - Handling Events RRS feed

  • Question

  • Hi,

     

                Is there a way to subscribe to the Sharepoint server events (not notification); whenever there is a change in document library (ie, add/update/delete) in a site as well as across sites (multiple sites that have document library)

     

                Can this be achieved using the Sharepoint object model - by extending the SPItemEventReceiver class.

     

                 Any links/pointers towards this would be appreciated.

     

                 Thanks in advance.

     

    --
    Abraham

    Tuesday, April 1, 2008 11:36 AM

Answers

  • You have almost answered your own question.

    See here for Handling document library events:
    http://msdn2.microsoft.com/en-us/library/ms868605.aspx

    Madhur
    Tuesday, April 1, 2008 12:17 PM
  • Event handler can be triggered for all sites in a site collection. For example if you have one web application on sharepoint server with one TOP level site collection along with 100 subsites in it. You can register event handler with your content type and event handler will trigger from all sites on all document libraries using the specific content type. This is useful if you want to trigger Event handler on specific document libraries using a content types.

    if your requirement is to trigger event handler on all document libraries regardless in a site collection, you can simply create a feature.xml file with its element.xml file and mention ListTemplateID=101. here is the feature help on MSDN

     

     

    http://msdn2.microsoft.com/en-us/library/ms475328.aspx

     

    and here are different ListTemplateIDs you can use

     

    GenericList 100
    DocumentLibrary 101
    Survey 102
    Links 103
    Announcements 104
    Contacts 105
    Events 106
    Tasks 107
    DiscussionBoard 108
    PictureLibrary 109

     

    Let me know if you have any question. If you used the above posted code or this reply to get started on event handler, please mark the particular reply as answered so that others can use the answered post as a helpful resource. thanks.

    Wednesday, April 2, 2008 5:40 PM

All replies

  • You have almost answered your own question.

    See here for Handling document library events:
    http://msdn2.microsoft.com/en-us/library/ms868605.aspx

    Madhur
    Tuesday, April 1, 2008 12:17 PM
  •  

    1- Create a class library project in Visual studio 2005

    2- Add Reference to ".NET" --> "Windows Sharepoint Services 3.0"

    3- create your class like this

     

     

     

    Imports Microsoft.SharePoint

     

    Public Class YourCustomEventReceiverName

    Inherits SPItemEventReceiver

     

    Public Overloads Overrides Sub ItemUpdating(ByVal properties As SPItemEventProperties)

     

    Dim oSPListItem As SPListItem = properties.ListItem

    MyBase.ItemUpdating(properties)

     

    'Update a column value if needed.

    properties.AfterProperties(oSPListItem.Fields("yourColName").InternalName) = "yourvalue"

     

    End Sub

     

    End Class

     

    4- Sign the dll and put in GAC.

    5- install this using a feature.

     

    Above sample is just a quick thing to show you how to get done your 1st event handler. You can register event handler to a template or to a specific document library or list etc. you can also register it with just content type so that it can get trigger from every document library or list where ever content type is existing.

     

    in above example i am in ItemUpdating. You can also use ItemUpdated event if you want to do some thing after item is updated by sharepoint. Updating is usually used if you want to update some meta values or wants to check some business rules to throw error back to user to correct few things.

     

    I hope it helps

    Tuesday, April 1, 2008 6:16 PM
  • Hi,

     

          Thanks for the earnest replies.

     

          We tried the above approach and was successful in getting events for a document library on a single site.

     

          We need to get events from across all sites within a SharePoint installation that have document library configured.

     

    >>you can also register it with just content type so that it can get trigger from every document library or list where ever >>content type is existing.

     

          From the above reply we were not able to figure out how the above could be achieved. Will this approach help us in tracking events raised across different sites ? Can you help us with some more details or pointers towards this.

     

    Thanks

     

    --

    Abraham

    Wednesday, April 2, 2008 9:57 AM
  • Event handler can be triggered for all sites in a site collection. For example if you have one web application on sharepoint server with one TOP level site collection along with 100 subsites in it. You can register event handler with your content type and event handler will trigger from all sites on all document libraries using the specific content type. This is useful if you want to trigger Event handler on specific document libraries using a content types.

    if your requirement is to trigger event handler on all document libraries regardless in a site collection, you can simply create a feature.xml file with its element.xml file and mention ListTemplateID=101. here is the feature help on MSDN

     

     

    http://msdn2.microsoft.com/en-us/library/ms475328.aspx

     

    and here are different ListTemplateIDs you can use

     

    GenericList 100
    DocumentLibrary 101
    Survey 102
    Links 103
    Announcements 104
    Contacts 105
    Events 106
    Tasks 107
    DiscussionBoard 108
    PictureLibrary 109

     

    Let me know if you have any question. If you used the above posted code or this reply to get started on event handler, please mark the particular reply as answered so that others can use the answered post as a helpful resource. thanks.

    Wednesday, April 2, 2008 5:40 PM
  • Hello all,

    I have a question about Sharepoint Event Receivers. I have a Sharepoint project which needs to run in Medium trust with all custom assemblies (webparts, event receivers) in the /bin folder. (Our Sharepoint installation is one of many on a shared server and so we are limited by not being able to add things to the GAC).

    Do you know if custom Event Receiver's are limited to running in the GAC, or should they work in Medium Trust in the /bin folder? I've tried them in the /bin folder and none of the events are firing - the assembly loads in debugger if I attach to the w3wp.exe process but none of my methods are called. I deploy the solution as a feature and I'm not getting any errors on deployment.

    Ant thoughts much appreciated


    Thanks

    Phil
    Friday, August 1, 2008 9:51 AM
  • I attached an event handler to a content type but the event just doesn't fire, I have no Idea why!! IS there any thing I am missing?
    Friday, January 16, 2009 11:33 PM