!Get All Users from SharePoint Person or Group Column
{
project: In one of my recent client project, I had a requirement send out a reminder to all users in Person or Group columns from custom tasks list in custom timer job. Job was working as long as you do not have any SharePoint local groups added to the Person or Group field. I thought it would be benefical to publish this specific solution
}

foreach (SPListItem task in items)
{
if (task["Status"].ToString() == "Incomplete")
{
//get all values from AssignedTo field
SPFieldUserValueCollection assignedTo = (SPFieldUserValueCollection)task["AssignedTo"];
if (assignedTo != null)
{
foreach (SPFieldUserValue spfuv in assignedTo)
{
//look for groups members;
if (spfuv.User == null)
{
SPGroup testGroup = web.SiteGroups[spfuv.LookupValue];
foreach (SPUser u in testGroup.Users)
{
// Do your custom code here
}
}
}
//regular users
else
{
// Do your custom code here
}
}
}
}


I will add full custom timer job code solution in next coming days

Last edited Oct 24, 2012 at 7:49 PM by venkyweb, version 3