Get field as SPUser from SPListItem -获取当中的用户

/// Gets the SPUser from field of Sharepoint list
/// 
/// <param name="aItem">The item.
/// <param name="aIntenalName">The internal field name
/// 
private SPUser GetSPUser(SPListItem aItem, string aIntenalName)
{
	SPFieldUser field = aItem.Fields.GetFieldByInternalName(aIntenalName) as SPFieldUser;

	if (field != null && aItem[aIntenalName] != null)
	{
		SPFieldUserValue fieldValue = field.GetFieldValue(aItem[aIntenalName].ToString()) as SPFieldUserValue;

		if (fieldValue != null)
		{
			return fieldValue.User;
		}
	}

	return null;
}

 Sharepoint list fields of type "User and Group" in object model as read as string, for example system field "Author", with this code you can getting this type of fields in the correct form. 

posted on 2012-02-10 14:12  SUNJUNLIN  阅读(467)  评论(0编辑  收藏  举报

导航