将 EventReceiver 附加到共享点站点的所有列表 [英] Attach EventReceiver to all lists of a sharepoint site

查看:15
本文介绍了将 EventReceiver 附加到共享点站点的所有列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们能否编写一个在任何列表更新时触发的事件接收器.我们必须为 eventreceiver 指定的 listtemplateid 使我们的代码特定于一种列表.如果我们想让代码对所有站点列表上的事件执行怎么办?

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?

推荐答案

我也有同样的需求.

也许可以将事件接收器附加到系统 ContentType(所有内容类型都继承该类型,id 为 0x)

Maybe it is possible to attach event receiver to System ContentType (all content types inherit that one, with id 0x)

我会通过使用 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.

  1. 尝试将 EventReceiver 添加到系统 (0x).调用方法 ContentType.Update(true,false) 更新所有子元素 - 系统 ContentType 也没有更新,子元素也没有更新.原来你不能用 ReadOnly || 修改那些 contentTypesSealed 属性设置为 TRUE
  2. 尝试将 EventReceiver 添加到项目 (0x01) ContentType.从这里可以看出,所有 ContentTypes 仍然继承自那个(参见 ContentType 层次结构).可能有自定义部署的内容类型继承自 System,但不是那些在 GUI 中制作的内容类型.更新此内容类型真正更新了所有子ContentTypes(除ReadOnlySealed 之外的所有内容类型)
  1. 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
  2. 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)

如何将全局 EventReceiver 附加到所有项目

因此,一个可行的解决方案如下所示:

How to attach a global EventReceiver to all items

So a solution which would work would look like this:

  1. 迭代所有列表,如果您希望那些内容类型与您的 EventReceivers 一起使用,请将 ReadonlySealed 设置为 false.
  2. 将您的 EventReceiver 添加到列表中的现有内容类型 (SPList.ContentTypes)
  3. 将 EventReceiver 添加到 ID 为 0x01 的 ContentType (SPWeb.ContentTypes),以便新列表自动添加 EventReceiver.新创建的内容类型也将继承 EventReceivers.此外,所有子网站 ContentTypes 都继承了 EventReceivers.
  1. Iterate all lists, set Readonly or Sealed to false if you want those content types with you EventReceivers.
  2. Add your EventReceiver to existing content types in lists (SPList.ContentTypes)
  3. 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 已本地化,但 {, , , ...} 表示我向内容类型添加了几个事件接收器.正如您所看到的,那些具有 ReadonlySealed 属性 False 的文件未受影响.

Sorry, my WSS is localized, but {, , , ...} means I added several eventreceivers to content types. As you can see those with Readonly or Sealed attribute False are untouched.

这篇关于将 EventReceiver 附加到共享点站点的所有列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆