Can we write an eventreceiver that gets fired when any list is updated. The listtemplateid that we have to specify for an eventreceiver makes our code specefic to one breed of lists. What if we want to have the code execute for events on all lists of site?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
I have the same exact requirement.
Maybe it is possible to attach event receiver to System
ContentType
(all content types inherit that one, with id 0x)I`d check if that's possible by creating a Feature with a FeatureReceiver and programmatically adding it to System Content Type. Some details here.
My path on finding a solution
Allright, I did some testing with console app.
EventReceiver
to System (0x). Called method ContentType.Update(true,false) which updates all child elements - nor did SystemContentType
updated, nor childs. Turns out that you cannot modify those contentTypes withReadOnly
||Sealed
attribute set toTRUE
ContentType
. As seen from here, allContentTypes
still inherit from that one (see ContentType hierarchy). There may be custom deployed content types that inherit from System, but not those made in GUI. Updating this content type truly updated all childContentTypes
(all content types except thoseReadOnly
orSealed
)How to attach a global EventReceiver to all items
So a solution which would work would look like this:
Readonly
orSealed
to false if you want those content types with youEventReceivers
.EventReceiver
to existing content types in lists (SPList.ContentTypes
)SPWeb.ContentTypes
) with id 0x01 so new lists get EventReceiver added automatically. Newly created content types will also inheritEventReceivers
. Also all subwebContentTypes
inheritEventReceivers
.All three steps could be a console application or powershell script. Or a site-collection wide feature with
FeatureReceiver
The result
Sorry, my WSS is localized, but {, , , ...} means I added several eventreceivers to content types. As you can see those with
Readonly
orSealed
attribute False are untouched.