Create a simple event Receiver in VS

Source: Internet
Author: User
Tags datetime

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.cn

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.
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.