It turns out that the field is (internaly) a look up field - which means it expects a number as an input.
You cant do :
- item["Assigned To"] = "administrator";
- item["Assigned To"] = "administrator@demo.com";
- item["Assigned To"] = "demo\\administrator";
Instead, you have to specify the user ID from the user's list:
item["Assigned To"] = 1;
But how to tell what ID does a user have?
The only way I know of is using the "Users" property of the SPWeb object. Lets say you want to assign the field to ishai@demo.com (you only know the email). you can use the following code:
item["Assigned To"] = item.ParentList.ParentWeb.Users.GetByEmail("ishai@demo.com").ID;
string [] domainName = new string[1];
domainName[0] = "demo\\ishai";
item.ParentList.ParentWeb.Users.GetCollection(domainName)[0];
Liked it? Please kick me!
2 comments:
Thanks for the tip.
How would you save multiple entries to the field/column from the people picker assuming the picker allows multiple selections?
I tried to separate the ids with ";", but it does not work.
Thanks again.
use something like:
string[] names = new string[] { "domain\\eric", "domain\\john" };
pass the names as your userlist.
Post a Comment