3
votes
 public override void ItemAdding(SPItemEventProperties properties)
       {
           base.ItemAdding(properties);
           SPItem itemBeingAdded = properties.ListItem;
           var startTime = itemBeingAdded["Start Time"];
           // Some code goes here.
       }

I am firing this event while adding an item in a calender list. It is getting fired. No problem. But I am not getting any value from properties. In the above code startTime gives me nothing. Actually, I want to access the column field of the item (properties in my case) is being added.

enter image description here

When the user will click in save button, How can I get the column value in code behind (Inside the ItemAdding(SPItemEventProperties properties) method). Let say, I need Start Time and End Time to compare them with some other values. Problem is in the ItemAdding method. ItemUpdating is working fine.

public override void ItemUpdating(SPItemEventProperties properties)
       {

           base.ItemUpdating(properties);
           SPItem itemBeingAdded = properties.ListItem;
           var startTime = itemBeingAdded["Start Time"];
       }
1
Did you inspect the contents of SPItemEventProperties? Is there an entry with the "Start Time" key? The internal names of fields may be different from what's displayed in the form. - Ondrej Tucny
Thanks for your response. I am going to try with internal name. - Atish Dipongkor
Result is same as before. Internal name is not working also. - Atish Dipongkor
Did you inspect the contents of SPItemEventProperties using your debugger's watch capability? - Ondrej Tucny

1 Answers

2
votes

Finally, I got my answer from here. The way would be like following

string message = properties.AfterProperties["Description"].ToString();

Another thing is you should use internal name. For my case, display name didn't work.