Get field as SPUser from SPListItem-取得中のユーザー

837 ワード

/// 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.