我将事件接收器附加到单个列表(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);
}
答案 0 :(得分:0)
答案 1 :(得分:0)
在Elements.xml文件中替换:
<Receivers ListTemplateId="100">
由
<Receivers ListUrl="Lists/Your List Name">