代码之家  ›  专栏  ›  技术社区  ›  Muhammad Hasan Khan

将EventReceiver附加到SharePoint网站的所有列表

  •  6
  • Muhammad Hasan Khan  · 技术社区  · 15 年前

    我们能写一个在任何列表更新时被激发的事件接收器吗? 我们必须为eventReceiver指定的listmaplateID使我们的代码特定于一类列表。如果我们想让代码为站点的所有列表上的事件执行呢?

    1 回复  |  直到 15 年前
        1
  •  8
  •   Janis Veinbergs    15 年前

    我有同样的要求。

    可能可以将事件接收器连接到系统 ContentType (所有内容类型都继承该类型,ID为0x)

    我会通过创建一个带有FeatureReceiver的特性并通过编程将其添加到系统内容类型来检查这是否可行。一些细节 here .

    我找到解决方案的途径

    好吧,我用控制台应用程序做了一些测试。

    1. 试图添加 EventReceiver 到系统(0x) . 调用了方法ContentType.Update(true、false),它更新所有子元素- 也没有系统 内容类型 更新,也不是儿童 . 结果发现,您不能用 ReadOnly γ Sealed 属性设置为 TRUE
    2. 尝试将EventReceiver添加到项(0x01) 内容类型 . 从这里看,所有 ContentTypes 仍然继承自那个(参见 ContentType hierarchy )可能存在从系统继承的自定义部署内容类型,但不是在GUI中生成的内容类型。更新此内容类型将真正更新所有子级 内容类型 (所有内容类型,除了那些 只读 密封的 )

    如何将全局事件接收器附加到所有项

    所以一个可行的解决方案是这样的:

    1. 迭代所有列表,设置 Readonly 密封的 如果您希望这些内容类型与您一起使用,则返回false EventReceivers .
    2. 加上你的 事件接收机 到列表中的现有内容类型( SPList.ContentTypes )
    3. 将EventReceiver添加到ContentType( SPWeb.ContentTypes )ID为0x01,因此新列表会自动添加EventReceiver。新创建的内容类型也将继承 事件接收器 . 也所有子网 内容类型 继承 事件接收器 .

    这三个步骤都可以是控制台应用程序或PowerShell脚本。或网站集范围内的功能 FeatureReceiver

    结果

        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
    

    抱歉,我的WSS已本地化,但、、…意味着我向内容类型添加了几个EventReceivers。就像你看到的那样 只读 密封的 属性false未被处理。