Friday, April 26, 2013

How to fetch user from multi-valued column in ItemEventReceiver



if you have muli-valued column of type Person or Group, the afterpropeties will give results in the format
"9;#Admin;#11;#Reader;#13;#Contribute";
To get the username or group names from the above string format, use the below code.

  char[] separators = new char[] { ';', '#' };
  object objgroupNamesNew = properties.AfterProperties["UserGroup"];
  string gNew = Convert.ToString(objgroupNamesNew);
  string[] gpnameNew = gNew.Split(separators, StringSplitOptions.RemoveEmptyEntries);
  var groupNamesNew = gpnameNew.Where((gp, index) => index % 2 != 0);
  foreach (var grp in groupNamesNew)
            {
                Console.WriteLine(grp);
            }

No comments:

Post a Comment