Hi All,
In a following example will demonstrate about how to use People Picker values in SharePoint.
Reading From People Picker Control:
SPFieldUserValueCollection PeopleCollection =new SPFieldUserValueCollection();
if (pplPickerID.ResolvedEntities.Count > 0)
{
foreach (PickerEntity pkrTlEnty in pplPickerID.ResolvedEntities)
{
SPUser spUser = web.EnsureUser(pkrTlEnty.Key);
PeopleCollection.Add(new SPFieldUserValue(web, spUser.ID, spUser.LoginName));
}
if (PeopleCollection != null)
{
sList["XXXX"] = PeopleCollection;
}
}
Bind Values to People Picker Control:
In a following example will demonstrate about how to use People Picker values in SharePoint.
Reading From People Picker Control:
SPFieldUserValueCollection PeopleCollection =new SPFieldUserValueCollection();
if (pplPickerID.ResolvedEntities.Count > 0)
{
foreach (PickerEntity pkrTlEnty in pplPickerID.ResolvedEntities)
{
SPUser spUser = web.EnsureUser(pkrTlEnty.Key);
PeopleCollection.Add(new SPFieldUserValue(web, spUser.ID, spUser.LoginName));
}
if (PeopleCollection != null)
{
sList["XXXX"] = PeopleCollection;
}
}
Bind Values to People Picker Control:
SPFieldUserValueCollection oPeopleCollection = ProDetails["ColumnName"] as SPFieldUserValueCollection;
if (oProjectManagerColl != null)
{
string managers = string.Empty;
foreach (SPFieldUserValue pplItem in oPeopleCollection)
{
managers += Convert.ToString(pplItem.User.LoginName) + ",";
}
pplPickerID.CommaSeparatedAccounts = managers.Remove(managers.LastIndexOf(","), 1);
}
Reading People User Value from the List Item:
1.
SPFieldUser field = risksItem.Fields.GetField("ColumnName") as SPFieldUser;
if (field != null)
{
SPFieldUserValue spfldrUserValue = field.GetFieldValue(Convert.ToString(risksItem["ColumnName"])) as SPFieldUserValue;
if (spfldrUserValue != null)
{
// place your code here
}
}
2.
SPFieldUserValueCollection UserCollection = (SPFieldUserValueCollection)ofield.GetFieldValue(oTaskItem["Assigned To"].ToString());
foreach (SPFieldUserValue user in UserCollection)
{
SPUser spAssignedUser = user.User;
}
0 comments:
Post a Comment