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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SP2010以编程方式将事件接收器附加到特定列表 - 针对所有列表运行相关的知识,希望对你有一定的参考价值。

我将事件接收器附加到单个列表(Web范围)。但ER运行Web中的所有列表。这个question说,部署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);
    }
答案

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

请参阅Here

检查帖子的结尾,在Elements.xml中将属性更改为“ListTemplateId”为“ListURL”

另一答案

在Elements.xml文件中替换:

<Receivers ListTemplateId="100"> by

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

以上是关于SP2010以编程方式将事件接收器附加到特定列表 - 针对所有列表运行的主要内容,如果未能解决你的问题,请参考以下文章

加入功能区buttonRibbon Button到SP2010特定列表或库

Sharepoint 2010以编程方式启动工作流程错误

COM 自动化 Excel 2010 冻结

SharePoint:如何以编程方式将项目添加到自定义列表实例

以编程方式更改值时触发 Dojo Select onChange 事件

如何将 UIPopover 附加到以编程方式创建的 CGRect