1

I have a task List and with an Event receiver , I am trying to get all the users that this task is assigned to. but when getting the item as "SPListItem" , the field assigned to is getting a sting and not a User , and this string is the First name of the User in the active Directory that isn't enough to get the user knowing that Name isn't Primary Key. what is the way to get the assigned users or group.

1
string fieldValue = Convert.ToString(task["Assigned To"]);
SPFieldUserValue assignedTo = (SPFieldUserValue)
task.Fields["Assigned To"].GetFieldValue(fieldValue);
2

Use can make use of SPUser to get the User object, from that object you can get all the informations about the user from Active Directory.

SPUser user = web.EnsureUser("FirstnameWhichyougotfromSPListItem") ;

Now make use of "user" to get the ID, name, email ID, etc.

OR

SPFieldUserValue value = new SPFieldUserValue(web, task["Assigned To"].ToString());

Now make use of value, to get the LoginName, lookupID, etc of the user.

hope this helps you.

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.