SP2010以编程方式将事件接收器附加到特定列表-对所有列表运行



我将事件接收器附加到单个列表(Web范围)。但是ER适用于网络中的所有列表。这个问题表明,ER部署在的功能必须是Web范围。事实就是这样。

该功能以编程方式激活,绑定到TLS中列表的ER。

newProjectWeb.Features.Add(new Guid("57e21870-6285-4e0a-b9a0-067f774492ae"));

请参阅下面的代码。我是不是错过了更新?

感谢您提前提供的帮助。

public void AddEventReceiverToMemberList()
    {
        try
        {
            _clsLists.AddEventReceiverToList(Web, ProjectMemberList.LIST_INTERNAL_NAME, typeof(SCMUProjectMemberList), SPEventReceiverType.ItemAdded);
            _clsLists.AddEventReceiverToList(Web, ProjectMemberList.LIST_INTERNAL_NAME, typeof(SCMUProjectMemberList), SPEventReceiverType.ItemDeleting);
            _clsLists.AddEventReceiverToList(Web, ProjectMemberList.LIST_INTERNAL_NAME, typeof(SCMUProjectMemberList), SPEventReceiverType.ItemUpdated);
            Web.Update();
        }
        catch (Exception)
        {
            throw;
        }
    }
public void AddEventReceiverToList(SPWeb web, string listName, Type eventReceiverClass, SPEventReceiverType eventType)
    {
        SPList list = this.GetListByName(web, listName);            
        string className = eventReceiverClass.FullName;
        string assemblyName = Assembly.GetAssembly(eventReceiverClass).FullName;
        list.EventReceivers.Add(eventType, assemblyName, className);
    }

如果要为单个列表运行事件接收器。。

参考此处

查看帖子的末尾,在Elements.xml 中将属性从"ListTemplateId"更改为"ListURL"

在Elements.xml文件中替换:

<Receivers ListTemplateId="100">通过

<Receivers ListUrl="Lists/Your List Name">

最新更新