An event sink is an effective way to add triggers to a SharePoint solution.
1. Create a testlist list at the site.
2. Admin Identity opens VS, creates event receiver events receiver.
3. Name Simpleeventreceiver, deploy as a farm solution, click Next.
4. Select list item events, announcements notification list, adding items.
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/
5. Click Finish.
6. Modify the SimpleEventReceiver.cs file, which adds a new item to another list:
Using System;
Using System.Security.Permissions;
Using Microsoft.SharePoint;
Using Microsoft.SharePoint.Security;
Using Microsoft.SharePoint.Utilities;
Using Microsoft.SharePoint.Workflow; namespace Simpleeventreceiver.simpleeventreceiver {///<summary>///list item Events///</summary> public class Simpl eeventreceiver:spitemeventreceiver {///<summary>///is adding items.///</summary> public override void Itemadding
(Spitemeventproperties properties)
{String eventName = "Event List:"; Base.
Itemadding (properties);
Loganannouncement (properties, eventName); private void Loganannouncement (Spitemeventproperties properties, String eventName) {string listtitle = properties.
List.title;
Be sure to replace the URL reference below with your//sharepoint server URL.
String mysiteurl = "http://smallville-pc:1528/";
DateTime currentdate = DateTime.Now; using (SPSite mysitecollection = new SPSite (Mysiteurl)) {using (SPWeb Myspsite = mysitecollection.rootweb) {SPList mySPList = myspsite.lists["Testlist"];
SPListItem Newlistitem = MySPList.Items.Add ();
newlistitem["Title"] = eventName + ListTitle + "@" + currentdate.tolongtimestring ();
Newlistitem.update (); }
}
}
}
}
7. Deployment.
8. In the Announcements notification list, add a new notification.
9. Navigating to the Testlist list will reveal new items.