Attach EventReceiver to all sharepoint site listings

Is it possible to write an eventreceiver that runs when any list is updated. The listtemplateid list that we must specify for the eventreceiver makes our code special for one list breed. What if we want the code to be executed for events in all the lists of the site?

+6
sharepoint moss
source share
1 answer

I have the exact same requirement.

Perhaps you can connect the event receiver to System ContentType (all content types inherit one, with id 0x)

I will check to see if this is possible by creating a Feature with FeatureReceiver and programmatically adding it to the System Content Type. Some details here .

My way to finding a solution

Ok, I tested the console application a bit.

  • I tried to add EventReceiver to the system (0x) . The ContentType.Update (true, false) method is called, which updates all child elements - and not the System ContentType , not the childs . Turns out you can't change those contentTypes using ReadOnly || Sealed set to TRUE
  • Tried adding EventReceiver to Item (0x01) ContentType . As you can see from this, all ContentTypes are still inherited from this (see the ContentType hierarchy ). Custom content types may exist that inherit from the System, but not those made in the graphical interface. Updating this type of content has really updated all ContentTypes child elements (all content types except ReadOnly or Sealed )

How to connect global EventReceiver to all elements

So, the solution that will work will look like this:

  • Iterate through all the lists, set ReadOnly or Sealed to false if you want these types of content to have EventReceivers with you.
  • Add EventReceiver to existing content types in lists ( SPList.ContentTypes )
  • Add EventReceiver to ContentType ( SPWeb.ContentTypes ) with id 0x01 so that new lists automatically add EventReceiver. New types of content also inherit EventReceivers . Also, all subweb ContentTypes inherit EventReceivers .

All three steps can be a console application or powershell script. Or a wide feature site with FeatureReceiver

Result

  PS C:\Documents and Settings\Administrator> $web.contentTypes |ft id, name, EventReceivers, readonly, sealed Id Name EventReceivers ReadOnly Sealed -- ---- -------------- -------- ------ 0x Sistēma {} False True 0x007F1DD730DB144C84... Darba kārtÄ«bas vēsture {} True True 0x01 Ieraksts {, , , ...} False False 0x01003420C661289843... Darba kārtÄ«bas ieraksts {, , , ...} False False 0x0101 Dokuments {, , , ...} False False 0x010100629D00608F81... Office datu savienoj... {} True False 0x010100B4CBD48E029A... Universālais datu sa... {} True False 0x010101 Veidlapa {, , , ...} False False 0x010102 Attēls {, , , ...} False False 0x010104 Nezināms dokumenta tips {} True False 0x010105 Lapu Å”ablons {, , , ...} False False 0x010107 Lietotāja darbplÅ«sma... {, , , ...} False False 0x010108 Wiki lapa {, , , ...} False False 0x010109 Pamatlapa {, , , ...} False False 0x01010901 Web daļu lapa {, , , ...} False False 0x01010A SaistÄ«t ar dokumentu {, , , ...} False False 0x01010B Dublinas pamata kolo... {, , , ...} False False 0x0102 Notikums {, , , ...} False False 0x0103 Diskutējamais jautājums {, , , ...} False False 0x0104 Paziņojums {, , , ...} False False 0x0105 Saite {, , , ...} False False 0x0106 Kontaktpersona {, , , ...} False False 0x0107 Ziņojums {, , , ...} False False 0x0108 Uzdevums {, , , ...} False False 0x0108007122AD6D76CD... Darba kārtÄ«bas uzdevums {, , , ...} False False 0x010801 DarbplÅ«smas uzdevums {, , , ...} False False 0x010802 AdministratÄ«vs uzdevums {, , , ...} False False 0x0109 DarbplÅ«smas vēsture {, , , ...} False False 0x010A Person {, , , ...} False False 0x010B SharePointGroup {, , , ...} False False 0x010C DomainGroup {, , , ...} False False 0x0110 Ziņa {, , , ...} False False 0x0111 Komentārs {, , , ...} False False 0x0116 Tālo Austrumu lÄ«gums {, , , ...} False False 0x0120 Mape {} False True 0x012001 RootOfList {} False True 0x012002 Diskusija {, , , ...} False False 

Sorry, my WSS is localized, but {,, ...} means that I added several types of events to the content types. As you can see, those with the ReadOnly or Sealed False attribute are not affected.

+8
source share

All Articles