Friday, 7 June 2013

Event reciver examples in sharepoint 2010

Itemdeleting event reciver
 public override void ItemDeleting(SPItemEventProperties properties)
           //listitem title name equal new that time event will fire
           if (properties.ListItem["Title"].ToString() == "new")

               properties.ErrorMessage = "Dont delete the item title starts with new";
        // firing event will restrict the user any action will happen
               properties.Cancel = true;
               properties.Cancel = false;
           //SPUtility.Redirect(properties.Web.Url, SPRedirectFlags.DoNotEndResponse, HttpContext.Current);


Itemadded event reciver

public override void ItemAdded(SPItemEventProperties properties)
           SPListItem item = properties.ListItem;
           //update only date for this column.if u add or update any data in the new date column..
           item["newdate"] = DateTime.Now.ToString();

No comments:

Post a Comment