Wednesday, December 8, 2010

Getting logged on user details in ItemAdding event in SPItemEventReceiver

I am writing a sharepoint 2010 Custom List event receiver. I am able to get the events which are happening on the list items however there's no obvious way to get the logged on user's details in ItemAdding Event. 
This is the event which occurs before the Item is added. 
SPContext.Current is null for some reason and hence its kind of a dead end to go towards this path. 
A non obvious way to achieve this is by using the following code snippet. 


public override void ItemAdding(SPItemEventProperties properties)
{

      SPUser user =               properties.OpenWeb().AllUsers.GetByID(properties.CurrentUserId)
}

~Abhishek

No comments: