Search This Blog

Friday, April 17, 2015

How to check a value is SPGroup or SPUser

SPList olist = oweb.Lists.TryGetList("Test_List");
if (olist != null)
{
SPListItemCollection ocoll = olist.Items;
foreach(SPItem oitem in ocoll)
{
SPFieldUserValueCollection GetAllGroup = new SPFieldUserValueCollection(oweb, Convert.ToString(oitem["SPGroups"]));

for (int i = 0; i < GetAllGroup.Count; i++)
{
SPFieldUserValue singlevalue = GetAllGroup[i];
if (singlevalue.User == null)   // If it is GROUP condition is true
{
SPGroup group = oweb.Groups[singlevalue.LookupValue];
foreach (SPUser user in group.Users)
{
if (ouser.Name == user.Name)
{
isuserval = true;
break;
}
}
}
else
{
if (ouser.Name == singlevalue.User.Name) // Checks User is Current Login User
{
isuserval = true;
break;
}
}
}
}
}


No comments:

Post a Comment

Restricting Custom People Picker to only one Sharepoint group programatically

Refer the following script files in your page,     <!-- For People Picker -->     <script type="text/javascript" src...