SPFieldUserValue User is null
-
10-12-2019 - |
Question
I have a list in which I can also view the version of each item. Suppose I have an item ItemX which has been modified by UserX, I then delete UserX and try to view the version item of ItemX which had been modified by UserX.
When I want to retrieve the information about ModifiedBy, the returned string value is null and I found it is because of this:
SPFieldUserValue userValue =
(SPFieldUserValue)userField.GetFieldValue(fieldValue.ToString());
SPUser user = userValue.User;//null
I thought of creating an SPUser, but found that there is no constructor available for that. Any ideas on how I can get around that problem? Thanks!
Solution
Try with EnsureUser method
SPUser user = web.EnsureUser(userValue.LoginName);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange