Adding value to PeoplePicker using code

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;

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;


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

Create a website or blog at

Up ↑

%d bloggers like this: