Tuesday, August 6, 2013

How to Retrieve the user name from Person or Group Field(People Finder) in SharePoint

How to Retrieve the SPUSer Valuesfrom people finder control .

The following function can be used to retrieve the user name and other properties from people finder controls.

There are two classes used here
1. SPFieldUser -- Gets the field or column onformation
2. SPFieldUserValue- -Gets the values from SPUSERFIELD


and here is the code ... enjoy....


 private SPUser GetSPUserNameFromIDEmailGAP(SPList GAPList, SPListItem ObjGroupAuditInformation)
        {

            try
            {
                SPUser user = null;

                
                if (GAPList != null)
                {
//gets the column name
                    SPFieldUser userField = (SPFieldUser)GAPList.Fields["ColumnName"];
//gets the value of spuser
                    SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(Convert.ToString(ObjGroupAuditInformation["Column name"];


                    if (fieldValue.User != null)
                    {

                        user = fieldValue.User; // you can have all other properties such as fieldvalue.email etc)


                    }

                }

                return user;
            }
            catch (Exception ex)
            {
               
                return null;
            }


        }

No comments:

Post a Comment

Rename a Web Application in Sharepoint : A solution using powershell

Here is a small script that will enable you all to change a SharePoint Web Application name . We can use the following SharePoint Pow...