maandag 3 november 2008

How to read an SPUser field

Ok... it's been a while since I last posted, but to make it up I have prepared a few posts for the coming time. Ranging from making dependant caching mechanisms in sharepoint to creating custom httpHandlers to host your masterpages centrally.
But first.. a post that I have created in june *blush*, but still didn't post.

It's just a little snippet I like, but always have to write again. So I'm going to save it here on my blog so I never have to do it again... at least until I finally create an own framework ;-).

public static SPUser GetSPUser(SPListItem item, string key)  {
SPFieldUser field = item.Fields[key] as SPFieldUser;
if( field != null) {
SPFieldUserValue fieldValue = field.GetFieldValue(item[key].ToString()) as SPFieldUserValue;
if(fieldValue != null)
return fieldValue.User;
return null;
}

Geen opmerkingen: