Check if the people picker has a user or a group in sharepoint Programatically

A quick tip to check if the account in the people picker field for an item is a User or a SharePoint group using code.

Code -
SPweb web = SPContext.Current.Web;

SPFieldUserValue _pickerValue = new SPFieldUserValue(web, item["PeoplePickerName"].ToString());

bool isUser = SPUtility.IsLoginValid(site, pickerValue.User.LoginName);

if (isUser)
{
// Its a SharePoint User
}
else
{

// Its a SharePoint Group

}

0 comments:

Post a Comment

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com