Find User from LookUp Field

 This code snippet is how to get user from the Lookup field here I am
leaving upto SPUser object.

 

objItem is List Item which has user/group LookUp Field

SPFieldLookupValue UserLookUPValue = new SPFieldLookupValue(objItem[“YourLookUPFieldName”].ToString());

 if (((SPFieldUserValueCollection)objItem[[“YOURLOOKUPFIELDNAME”]).Count > 0)

 {

     while (intUserCount < ((SPFieldUserValueCollection)objItem[“YOURLOOKUPFIELDNAME”]).Count)

     {

         if (((SPFieldUserValueCollection)objItem[“YOURLOOKUPFIELDNAME”])[intUserCount].User != null)

         {

             //If field contain user name

             SPUser objUser = ((SPFieldUserValueCollection)objItem[“YOURLOOKUPFIELDNAME”])[intUserCount].User;

            

                  //Here you can write your Business Logic 

 

         }

         else

         {

             //If field contain group name

             string strGroupName = ((SPFieldUserValueCollection)objItem[“YOURLOOKUPFIELDNAME”])[intUserCount].LookupValue;

             try

             {

                 SPGroup objGroup = objSPWeb.SiteGroups[strGroupName];

                 if (objGroup.Users.Count > 0)

                 {

                     SPUserCollection objUsers = objGroup.Users;

                     foreach (SPUser objuser in objUsers)

                     {

                  //Here you can write your Business Logic 

                     }

                 }

             }

             catch(Exception Ex)

             {

             }

         }

         intUserCount++;

     }

 }

 

Happy coding  🙂