Tuesday, May 12, 2009

Operations related to SharePoint's Column type Person or Group

In this post I discussed how we can fetch records from SPListItem's column type Person or Group and stored information back into that column.

Here in following method first I am creating the SPUser by using EnsureUser method of SPSite and then adding that SPUser in SPListItem of SPList. Then I am fetching that SPUser from the SPListItem.

(In Folloing method codes with comments are self-explainatory)



/// <summary>
/// Working with with column of type [Person OR Group]
/// </summary>
void user()
{
//SPListItem spListItem;

string loginName = "DOMAIN\\USERNAME";
//Assign SPUser in your custom column and
//also its Login name (string) in seperate column
//(for ease in development operation)
spListItem["User"] = oWebsite.EnsureUser(loginName);
spListItem["UserLoginName"] = loginName;


//Fetch SPUser values from SPColumn
SPFieldUserValueCollection values
= (SPFieldUserValueCollection)spListItem["User"];
loginName = values[0].User.LoginName;
}



Note : From UI control point of view, we can use SharePoint's PeoplePicker control to enter and validate SPUser.

1 comment:

Ran said...

My current project requires ability to display choice column value via color or image associated with a choice

But Sharepoint standard packaged misses that control

I am looking for available solutions on market

I came across

http://amazepoint.com/Products/VisualChoiceColumn/Overview.aspx>


Does anybody has experiece using it?

Google