我正在處理一個項目,我在SharePoint 2010中有幾個站點。每個站點下都包含一個包含新聞的列表,並且我希望將一個事件接收器附加到這些列表。如何以編程方式將Event Receiver附加到SPList?
下面的站點和列表是以編程方式創建的,但我無法附加我在VS2010解決方案中使用的事件接收器。
我試過這個:
SPList list = new SPSite(siteURL).OpenWeb().Lists[listName];
SPEventReceiverDefinitionCollection eventReceivers = list.EventReceivers;
SPEventReceiverDefinition eventReceiver = eventReceivers.Add();
eventReceiver.Name = receiverName;
eventReceiver.Synchronization = SPEventReceiverSynchronization.Synchronous;
eventReceiver.Type = SPEventReceiverType.ItemAdded;
eventReceiver.SequenceNumber = sequenceNumber;
eventReceiver.Assembly = assemblyFullName;
eventReceiver.Class = assemblyClassName;
eventReceiver.Data = receiverData;
eventReceiver.Update();
但它不工作。
錯誤消息是「無法加載文件或程序集'Projekt_Test1 \,\,Version \ = 1.0.1777.23493 \,Culture \ = neutral \,PublicKeyToken \ = 49c7547d535382ab'或其某個依賴項。或代碼庫無效。(來自HRESULT的例外:0x80131047)「
感謝您的幫助。
真棒,謝謝了一堆。 –