var field = item["user"]
you just get a string with User ID , like : "123;#"
We need to cast this object to SPFieldUserValue.
This C# code can help us:
public SPUser GetSPUserObject(SPListItem spListItem, String fieldName) { SPUser spUser = null; try { if (fieldName != string.Empty) { SPFieldUser field = spListItem.Fields[fieldName] as SPFieldUser; if (field != null && spListItem[fieldName] != null) { SPFieldUserValue fieldValue = field.GetFieldValue(spListItem[fieldName].ToString()) as SPFieldUserValue; if (fieldValue != null) { spUser = fieldValue.User; } } } } catch (Exception ex) { throw ex; } return spUser; }
No comments:
Post a Comment