Scenario:
Reading values from People picker control
Solution:
Here's I am posted sample code, Sorry for hardcoding the item id and other values.Please make changes according to requirement.
Single User/Group selection:
Multi User/Group selection:
using(SPSite site = new SPSite("http://localhost"))
{
using(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Tasks"];
SPListItem item = list.GetItemById(1);
SPFieldUserValue userValue = new SPFieldUserValue(web, item["AssignedTo"].ToString());
Console.WriteLine(userValue.User.Email);
}
}
using(SPSite site = new SPSite("http://localhost"))
{
using(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Tasks"];
SPListItem item = list.GetItemById(1);
SPFieldUserValueCollection userValue = new SPFieldUserValueCollection(web, item["AssignedTo"].ToString());
Console.WriteLine(userValue[0].User.Email);
}
}
1 comments:
Helped me! thanks a lot...
Post a Comment