none
Retrive field information from item in Event rciver Delete Item

    Question

  • Hi guys,

    i have a reciver on a sharepoint specific list with a deleteItem event. I have to retrive ID  value of the item that will delete before the deleting process is ti possible?

    Thank you!

    Wednesday, September 25, 2013 8:05 AM

Answers

  • Hello,

    You can use properties to get current list item column values like:

    public override void ItemDeleting(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);
            
            int itemId = properties.ListItemId;
           //If you wnat to get another column value then use belwo code
           string title = properties.ListItem["Title"];
        }
    
    public override void ItemDeleted(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);
            
            int itemId = properties.ListItemId;
           //If you wnat to get another column value then use belwo code
           string title = properties.ListItem["Title"];
        }

    You can refer thsi to get more detail of list/item/column/site etc using properties:

    http://sprider.org/2011/10/15/get-next-list-item-id-in-sharepoint-list/

    Hope it could help


    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by gohberto Wednesday, September 25, 2013 9:57 AM
    Wednesday, September 25, 2013 9:35 AM
    Moderator

All replies

  • yes it is possible, the deleteitem method will have a SPItemEventProperties as its one of the input parameter you can retrieve the id from that parameter

    Regards,


    Sairam Avacorp Technologies

    Wednesday, September 25, 2013 8:13 AM
  • Hello,

    You can use properties to get current list item column values like:

    public override void ItemDeleting(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);
            
            int itemId = properties.ListItemId;
           //If you wnat to get another column value then use belwo code
           string title = properties.ListItem["Title"];
        }
    
    public override void ItemDeleted(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);
            
            int itemId = properties.ListItemId;
           //If you wnat to get another column value then use belwo code
           string title = properties.ListItem["Title"];
        }

    You can refer thsi to get more detail of list/item/column/site etc using properties:

    http://sprider.org/2011/10/15/get-next-list-item-id-in-sharepoint-list/

    Hope it could help


    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by gohberto Wednesday, September 25, 2013 9:57 AM
    Wednesday, September 25, 2013 9:35 AM
    Moderator
  • This sample should work for you as well.

    public class TrackDeletedItems : SPItemEventReceiver
        {
            string _source = "TrackDeletedItems";
            string _log = "Application";
            string _event = string.Empty;

            public override void ItemDeleting(SPItemEventProperties properties)
            {
                base.ItemDeleting(properties);

                int itemID = properties.ListItem.ID;
                string itemGUID = properties.ListItem.UniqueId.ToString();
                string itemTitle = properties.ListItem.Title;

                _event = "The list item with ID: " + itemID + " and GUID: " + itemGUID + " and title: " + itemTitle + " has been deleted successfully.";

                if (!EventLog.SourceExists(_source))
                    EventLog.CreateEventSource(_source, _log);

                EventLog.WriteEntry(_source, _event, EventLogEntryType.Information, 1234);
            }
        }

    HTH!


    These postings are provided "AS IS" with no warranties, and confers no rights.

    Wednesday, September 25, 2013 9:42 AM