Adding value to PeoplePicker using code

Posted: August 7, 2009 in Code, People Picker

If you are using a people picker control of sharepoint in your web page or if you want to update a People and group column of a list item, you cant update the item by using a string value (in my case loginUser).

string loginUser= Convert.ToString(ViewState[“accountname”]);
item[“To”] = loginUser;
Item.Update();

This above code will throw an error for invalid datatype.
So we have to input a SPUser object to the item which can be done as below.

string loginUser= Convert.ToString(ViewState[“accountname”]);
SPUser user = site.Users[loginUser];
item[“To”] = user;
Item.Update();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s