1

I have a requirement that I have to get the list item values in SharePoint list item updating event. In that I am getting list item properties( current properties ) and also updated values( after properties ), except the people picker value.

as that

string cuurentUser= properties.ListItem["User"].ToString();
( Result: "22;#RAMPINDIA/ventew")
string afterUser= properties.AfterProperties["PermissionLevel"].ToString(); (Result:"22")

as shown above I am just getting the ID only.

Can any one help me to find the way to find the entire name?

  • Based on your sample, it would seem that you aren't reading the before and after values from the same field... Is that right? – Hitodama Dec 15 '11 at 14:35
  • yes, in after properties iam reading all fields except the people picker value... – suresh Dec 16 '11 at 3:49
2

If you are accessing to lookup field in AfterProperties, you always get only lookup id. User field is also lookup to User Information List, so you must get user using GetById(int ID) as @Stuart Pegg suggests. But there are some pitfalls when you accessing to lookup fields in event receivers, I've posted about this pitfalls in my blog, check it out:

Accessing SharePoint lookup fields values in item receivers - some pitfalls
Working with SPFielduserValue in item event receivers - some pitfalls

1

I believe you should be able to use the SPWeb.AllUsers.GetById(int ID) method to get the SPUser for that ID, and then use that object's properties to get the required information:

MSDN: SPUserCollection.GetByID Method

MSDN: SPUser Members

Also, you can use SPFieldUserValue(SPWeb, string) constructor to get an SPFieldUserValue object from your current properties string, and use SPFieldUserValue.User to get an SPUser object. More details on using SPFieldUserValue can be found on my blog:

TssTssT: Easily accessing Lookup and User fields

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.