Getting SPUser from SharePoint List Column

In the project I was working on right now, I had to get a User field from a SharePoint User colum. The value is stored as a lookup column and in order to get it as a SPUSER I had to write the following utility method

public static SPUser GetUser(string columnValue, SPField userField)

{

SPFieldUser field = (SPFieldUser)userField;

SPFieldUserValue fieldValue = (SPFieldUserValue)field.GetFieldValue(columnValue);

return fieldValue.User;    

} 

    To get the SPUSer filed now, we just call the method as follows

        string managerColumnValue =

            nominationListItem[NominationListColumns.MANAGER].ToString();

    SPUser manager = Utilities.GetUser(managerColumnValue,

    nominationListItem.Fields[NominationListColumns.MANAGER]);

   

    where

        NominationListColumns.MANAGER = "Manager", which is the column name..

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.