我们可以写时会触发任何列表更新的eventreceiver。 我们必须指定一个eventreceiver的listtemplateid使我们的code specefic到列表中的一个品种。如果我们想在网站列出的所有事件的code执行?
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?
推荐答案
我有同样的确切要求。
I have the same exact requirement.
也许是可能的事件接收器连接到系统的ContentType
(所有内容类型继承的,ID为0X)
Maybe it is possible to attach event receiver to System ContentType
(all content types inherit that one, with id 0x)
I`d检查,如果这是可能通过创建一个FeatureReceiver一个功能和编程方式将它添加到系统的内容类型。一些细节这里。
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.
还好吧,我与控制台应用程序,一些测试。
Allright, I did some testing with console app.
尝试添加 EventReceiver
以系统(0X)。调用方法ContentType.Update(真,假),这将更新所有子元素 - 也没有系统的ContentType
更新,也没有孩子的。事实证明,你不能修改这些contentTypes与只读
|| 密封
属性设置为 TRUE
尝试添加EventReceiver项(0x01)的的ContentType
。正如从这里看到的,所有的 ContentTypes
还是从一个继承(见的 ContentType的层次)。有可能是定制的部署,从系统继承的内容类型,但在图形用户界面不是那些发。更新此内容类型真正更新的所有子 ContentTypes
(所有类型的内容,除了那些只读
或密封
)
Tried to add EventReceiver
to System (0x). Called method ContentType.Update(true,false) which updates all child elements - nor did System ContentType
updated, nor childs. Turns out that you cannot modify those contentTypes with ReadOnly
|| Sealed
attribute set to TRUE
Tried to add EventReceiver to Item (0x01) ContentType
. As seen from here, all ContentTypes
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 child ContentTypes
(all content types except those ReadOnly
or Sealed
)
那么,哪会工作的解决方案是这样的:
How to attach a global EventReceiver to all items
So a solution which would work would look like this:
在遍历所有的列表,设置只读
或密封
为false,如果你想和你的内容类型 EventReceivers
。
添加您的 EventReceiver
现有的内容类型的列表( SPList.ContentTypes )
添加EventReceiver到的ContentType( SPWeb.ContentTypes
)ID为0×01,以便新的列表得EventReceiver自动添加。新创建的内容类型也将继承 EventReceivers
。此外,各子网站 ContentTypes
继承 EventReceivers
。
Iterate all lists, set Readonly
or Sealed
to false if you want those content types with you EventReceivers
.
Add your EventReceiver
to existing content types in lists (SPList.ContentTypes
)
Add EventReceiver to ContentType (SPWeb.ContentTypes
) with id 0x01 so new lists get EventReceiver added automatically. Newly created content types will also inherit EventReceivers
. Also all subweb ContentTypes
inherit EventReceivers
.
这三个步骤,可以是一个控制台应用程序或PowerShell脚本。或用 FeatureReceiver
All three steps could be a console application or powershell script. Or a site-collection wide feature with FeatureReceiver
PS C:Documents and SettingsAdministrator> $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
对不起,我的WSS是局部的,但{,,,...}意味着我添加了几个eventreceivers内容类型。正如你所看到的那些只读
或密封
属性假的不变。
相关推荐
最新文章