Getting the SPUser out of SPFieldUser

August 02, 2007

SPFieldUser field type stores the username in "1#;User" fashion. This is a small annoyance when trying to access the user data, for instance when parsing "Assigned To" field of a Tasks list item.

This small amount of code will allow you to quickly get the underlying SPUser object. In this example, the SPFieldUser is the "Assigned To" column.

SPFieldUser assignedTo = (SPFieldUser)task.Fields[SPBuiltInFieldId.AssignedTo];

SPFieldUserValue user = (SPFieldUserValue) assignedTo.GetFieldValue(task[SPBuiltInFieldId.AssignedTo].ToString());

SPUser userObject = user.User;


Profile picture

Written by Edin Kapić Insatiably curious code-writing tinkerer. Geek father. Aviation enthusiast. Cuisine journeyman. Follow me on Twitter