domingo, 19 de outubro de 2008

How to get SharePoint users from peoplePicker?

Get peoplePicker string text, and convert it to an int array list of users’ index


public static int[] GetUserIndexesFromPeoplePicker(string users)
{
int nUsers;
int[] indexes;
if (users == null users.Trim().Length == 0)
return null;
string[] splited = users.Split(new char[] { '#', ';' },
StringSplitOptions.RemoveEmptyEntries);
if (splited.Length < 2 splited.Length % 2 != 0)
return null;
nUsers = splited.Length / 2;
indexes = new int[nUsers];
for (int i = 0, j = 0; j < nUsers; i += 2, ++j)
indexes[j] = int.Parse(splited[i]);
return indexes;
}


Or, get a string text from peoplePicker and convert it to a string array list of login names,


public static string[] GetUserNamesFromPeoplePicker(string users)
{
int nUsers;
string[] userNames;
if (users == null users.Trim().Length == 0)
return null;
string[] splited = users.Split(new char[] { '#', ';' },
StringSplitOptions.RemoveEmptyEntries);
if (splited.Length < 2 splited.Length % 2 != 0)
return null;
nUsers = splited.Length / 2;
userNames = new string[nUsers];
for (int i = 1, j = 0; j < nUsers; i += 2, ++j)
userNames[j] = splited[i];
return userNames;
}


Enjoy!!!

Sem comentários: