February 20, 2014

SharePoint How to get SPUser from list item C#

How to get SPUser from list item, SharePoint list item get user, how to get created, modified, Author or Editor from sharepoint list, how to get LoginName or Email of User from list,

Well there is another way to get Web. EnsureUser(“User”); it returns SPUser object as well it adds user in site directly if do not already that web user, another way to get it write a function that return SPUser object,   

*Assuming that you are aware how to get SPWeb and List then List item,

SPUser oUserSubmittedBy = GetSPUser(oItem, “fieldDisplay Name”);

Here is the function body.

protected SPUser GetSPUser(SPListItem item, string user)


            SPUser oUser = null;

            SPFieldUserValue userValue = new SPFieldUserValue(item.Web, Convert.ToString(item[user]));

            if (userValue != null)


                oUser = userValue.User;


            return oUser;


And once you get object you can get Name, email and login name

oUserSubmittedBy.Email…. etc..

Praveen Pandit